Use a spudger to loosen the right speaker cable's connector from its socket on the logic board.
It is useful to push downward on both short sides of the connector to "walk" it out of its socket. Be careful with the corners of the connectors, they can be easily broken off.
Pull the connector downwards to remove it from its socket.
Pull the right speaker straight up about an inch, toward the top of the iMac.
Lift the right speaker straight up and remove it from the iMac. This may take some force, both hands and rocking the speaker right and left to get it out.