I would write y as a power series: \(\displaystyle y= \sum_{n=0}^\infty a_nx^n= a_0+ a_1x+ a_2x^2+ \cdot\cdot\cdot\). Then \(\displaystyle y'= a_1+ 2a_2x+ 3a_3x^2+ \cdot\cdot\cdot\), \(\displaystyle xy= a_0x+ a_1x^2+ a_2x^3+ \cdot\cdot\cdot\), and \(\displaystyle cos(x)= 1- \frac{x^2}{2}+ \frac{x^4}{24}+ \cdot\cdot\cdot\) so that equation becomes
\(\displaystyle a_1+ 2a_2x+ 3a_3x^2+ 4a_4x^3+ 5x^4+ \cdot\cdot\cdot+ a_0x+ a_1x^2+ a_2x^3+ a_3x^4+ \cdot\cdot\cdot= a_1+ (2a_2+ a_0)x+ (3a_3+ a_1)x^2+ (4a_4+ a_2)x^3+ (5a_5+ a_3)x^4+ \cdot\cdot\cdot= 1- \frac{x^2}{2}+ \frac{x^4}{24}+ \cdot\cdot\cdot\).
Since this is to be true for all x, the coefficients of equal powers of x must be equal:
\(\displaystyle a_1= 1\)
\(\displaystyle 2a_2+ a_0= 0\)
\(\displaystyle 3a_3+ a_1= \frac{1}{2}\)
\(\displaystyle 4a_4+ a_2= 0\)
\(\displaystyle 5a_5+ a_3= \frac{1}{24}\)
etc.
We can take \(\displaystyle a_0\) to be the "constant of integration"
\(\displaystyle a_0\), \(\displaystyle a_1= 1\), \(\displaystyle a_2= -\frac{a_0}{2}\), \(\displaystyle a_3= \frac{1}{6}- \frac{a_1}{3}= \frac{1}{6}- \frac{1}{3}= -\frac{1}{6}\),
\(\displaystyle a_4= -\frac{a_2}{4}= \frac{a_0}{8}\),
\(\displaystyle a_5= -\frac{a_3}{5}+ \frac{1}{120}\),
etc.