You can see where this is going. Black is threatening mate. But he also has his own king and queen on adjacent diagonal squares; so White looks for a pin and finds it with Bd4. It looks perfect because the bishop gets protection from the rook on d1. But this position illustrates a risk to consider when building a pin: your opponent may be able to interpose something between the pinning and pinned pieces. In this case Black will play e6-e5. Now what? One option is simply to take the pawn with Bxe5, renewing the pin on the queen. The problem is that White’s bishop would then lose its protection from the rook.
Still, don’t assume the idea must therefore be a failure. Imagine Black actually playing QxB; ask what would then be possible for White, especially by way of an attack on Black’s king. Really White has just one piece usable for that purpose: his own queen, which he can play to...h6! Fortunately that’s enough; Qh6 is mate because the Black king’s position is so constrained. (A king stuck in the corner with no pawn cover is at great risk.)
So it turns out that Black’s queen is not free to take the bishop that pins it, and that Bd4, followed by Bxe5, is a winning sequence for White. The general point is that when you have a possible pin, don't lightly dismiss the idea just because your pinning piece could be taken. Pause to ask what would be possible on the board as it then would look, asking the same questions about that resulting position (looking for possible checks, forks and the like) that you ask about the board in front of you.