This is an issue with the order of operations in your code.
The best way to solve this is break your code into small manageable functions. When you write code, try to make simple functions which return values and test to see whether these functions work. Breaking up code in this way is a important skill for manageable and debuggable code.
Here is a function that returns an InterpolationFunction for a given value of some parameter:
functionMaker[param_?NumericQ] := Module[{y, x}, y /. First@NDSolve[{y'[x] == y[x] Cos[x + param y[x]], y[0] == 1}, y, {x, 0, 30}]]
The Module is there to localize y and x. Please see
this article on why ?NumericQ was used in the definition of functionMaker. This function can be tested and we can verify that it works correctly before continuing with the rest of the problem.
Plot[functionMaker[1][x], {x, 0, 10}]
Animate[Plot[functionMaker[n][x], {x, 0, 10}], {n, 1, 5, 0.1}]
You may also condsider using ParametricNDSolve for this kind of problem.