In this case it's tactical. d4 looks like a really strong move but the problem is after 12...d4 13. Bxf6 black has to play 13...gxf6 because 13...Qxf6 drops a piece to 14.Ne4.
However, if you play 13...g5 first followed by d4, then d4 trades off the isolated pawn and equalizes for black. Black also has a little bit of an initiative going at that point.
In general, you don't want to move the pawns in front of your king if you don't have to or unless it benefits you (like in this example).
How to deal with pins? Study unpin combinations. There are a lot with sacs on f7/f2 and h7/h2. There are also some where the knight captures like Legal's mate or captures on d4/d5 sometimes winning a piece.
You can also play actively. For example creating a threat with the queen and then moving the knight to a center square or just playing aggressively in general will sometimes make the pin meaningless. You also have to remember an early pin by the queen's bishop is usually bad. For one it leaves the b pawn unprotected but also if you haven't castled on that side he isn't really threatening anything.
Lastly, if the opponent captures and doubles your pawns that's not always bad. For one, that means you have the two bishops and an open g-file which is typically the file right in front of the opponent's king. It depends on the position but it's not uncommon for your opponent to hand you a ferocious attack by capturing the knight.
Just as an example, to illustrate some points, this is a game I see at least once a week in blitz:
1. e4 e5 2. Bc4 d6 3. d4 exd4 4. Nf3 Bg4 5. c3 Nc6 6. Qb3 with a double attack on both b7 and f7. Black has a lot of ways to go wrong in this position and 6...Bxf3 (which leads to 7. Bxf7+, Ke7 or d7 8. Qe6#) is fairly common.