1. The queen can easily move out of this so while it does attack the queen, you are already in the deep middle game so moving the queen to a powerful square like a5 in this situation means white does not lose a tempo and gains an advantage which lets them create many additional attacks, because of this, the move does not have any extremely damaging effects for white.
2. Secondly, the move cxd4 is good since that knight is a very active piece and capturing it will save you a lot of potential problems, as an example, if white managed to make you move your f7 pawn forward, they could play Ne6+ which forks the king and queen, since the f7 pawn moved you cannot capture the knight and you cannot protect using another piece since the check is with a knight, because of this you are forced to move your king away and will therefore lose your queen, this is probably the more important reason.
If I have captured opponent's knight, then he would have easily escaped from this situation.