I am not sure what exactly giving you trouble. I try to explain in the following way:

The first step here is necessary - and is more general. I believe that in this question it was assumed that are independent so that the condition probability can be safely changed to the ordinary one in the 3rd line. But in general they can be dependent and you cannot do so.

Or you may view this in other perspective: