What is the purpose of hanging the b and g pawns?

Most of the time, the b and g pawns are taken by the enemy queen. Also most of the time, this results in the queen getting stuck in an awkward position or even straight up trapped, and allows the other side to continue normal development while hindering the opponent by attacking their queen.
It's rarely "intentional," though. Most of the time they just end up unprotected because the bishops have to come out eventually, unless the player opts to fianchetto them.