How do Goku and Gohan manage to turn into great apes in Dragon Ball and Dragon Ball Z? From what I know, they look at the full moon with their tails still intact before they turn into great apes, or "ozaru" as it is called in Japanese. 

How does their transformation work?
Saiyan's have an ability which allows them to transform into a Great Ape, which comes along with a massive power boost making them even stronger.The premise of your question basically answers how the transformation happens. With reference to what exactly happens after, apart from the transformation change as described, the Saiyan's power increases 10 folds. You can read more about the transformation here.