I think this is a great question because it is really about the ambiguous/confusing way we use the word polynomial. So I want to use the terms "polynomial" and "polynomial function" separately here.
A polynomial is an algebraic expression. It consists of variables and coefficients and only uses the operations of addition, subtraction, multiplication, and non-negative integer exponents. That is Wikipedia's definition and is in the plainest language that I found, but it matches definitions found in undergraduate algebra textbooks like Lang.
A polynomial function is a function that can be defined by evaluating a polynomial. It can be defined that way; it doesn't have to. However, you pick up any precalculus or calculus textbook and this is not what you'll find. For example, in Stewart's Calculus:
A function P$P$ is called a polynomial if $P(x) = a_nx^n + ... + a_0$ where $n$ is a nonnegative integer and the numbers $a_i$ are called the coefficients.
So he uses the term differently. However, this definition is effectively the same as Wikipedia's definition of polynomial function if we think about what it means to be equal as functions. Two functions are equal if $f(x) = g(x)$ for every $x$ in the domain of f$f$ and g$g$. The domains have to match, and every value has to match. Those functions are the same. They are one function with two different expressions. In your example, $f(x)=\frac{(x^2+1)x^3}{x^2+1}$ is equal to $g(x)=x^3$ for every real number, so they are both polynomial functions.
When we're talking about algebraic expressions, on the other hand, the quality of being a polynomial doesn't have to be preserved when you alter the expression. $\frac{(x^2+1)x^3}{x^2+1}$ is equivalent to $x^3$, but they are not the same expression. One is a polynomial and the other is not.
Finally, a fancier example from Lang:
In some cases, it may be that two polynomials can be distinct, but give rise to the same polynomial function on a given ring. For example, let $\mathbb{F}_p=\mathbb{Z}/p\mathbb{Z}$ be the field with $p$ elements. Then for every element $x\in\mathbb{F}_p$ we have $x^p=x$.
So you have different polynomials, but the same polynomial function.