To what extent should you prevent your opponent from castling? I normally try to prevent my opponent from castling if possible, by forcing their king to move or keeping an attacking piece on a diagonal or file.

I tend to make this a priority, giving up the opportunity to capture a pawn or pursue a different strategy early on.

Does this make sense? Would I be better off capturing a pawn if I can? Is preventing castling something that should be given priority, or is it more of an afterthought?
Can you try answering why are you trying to prevent your opponent from castling?

When you think about this more - you realize that castling prevention is just a tactical weapon, nothing more. Of course you can win a game if you are good at tactics, if your opponent makes mistakes, but, to quote Alekhine: 


  "It took me many years to get rid of the bias that I can win in any
  position, even in a bad one, using some amazing combination".


The need for playing to prevent your opponent from castling is dictated by the position on the board. Of course it makes sense to follow this plan if you achieved some development advantage in the beginning of the game, your pieces are more active and you have good chances to start a massive attack against the enemy king that's trapped in the middle. Of course, sacrificing a pawn (or even more pieces) in this case is justified, since your positional advantage will compensate that.

What if you can't prevent your opponent from doing multiple exchanges after you sacrificed a pawn? Losing many active pieces (due to exchanges) will reduce your attacking potential. And you will have to play an endgame without a pawn. If your opponent is better than you at endgame - he will force those exchanges with the endgame in mind - entering it in a better (or even won) position. Since he will have at least two advantages over you:


+1 pawn
king in the middle (assuming you castled), which is considered an advantage in endgame


This is very important to consider, since often even a single exchange (of queens) serves as green light to endgame.