$$y' - y \tan x = 2x \sec x\tag1$$$$\cdots\\I.F. y = \int I.F.\ 2x\ \sec x\ dx\\(\cos x) y = \int \cos x \ 2x\ \sec x\ dx = \int 2x\ dx$$
If we had taken the integrating factor to be $|\cos x|$, then in the above line $|\cos x|$ and $\sec x$ wouldn't have cancelled.
They would still have cancelled out. The absolute-value function just means that you have to break the equation up into two cases, negative $\cos x$ (here $|\cos x|=-\cos x$) and nonegative $\cos x=$ (here, $|\cos x|=\cos x$); notice that for the negative case, there are two extra minus signs in the equation, one on each side; so, the two cases then recombine into the original single case.
integrating factor $= e^{-\int \tan x\ dx} = e^{\ln|\cos x|} = \cos x$
Can we write $|\cos x|$ as $\cos x$ above?
I explained here that not only can you drop the absolute-value sign, you can even frivolously say that $$e^{\ln (-34\cos x)}$$ is an integrating factor of $(1).$ The $-34$ will cancel out for the same reason as above. So, to be pedantically accurate, it's not so much that the integrating factor of $(1)$ equals $\cos x,$ but that $\cos x$ is an integrating factor of $(1).$