depends on the position. my coach says that if you can castle, and it is safe, then it is almost always in the top 3 moves. However, if your opponent is already launching an attack, then of course it would be unwise to castle in that direction.
Castle Opposite or ASAP

Watch some master-level games on a Youtube channel like agadmator's and see how seldom masters play games where castling happens on opposite sides.

Castle with a purpose.
King safety: if the center is fluid and open(ing) up then it is a good idea to get your king out of the center. Also, if the center is locked up then castling *may* not be so important because the king may be safer in the center (when the center locks attacks go toward the wings).
Attack: You may notice that in Morphy games he gets his pieces out quickly, opens up lines (usually in the center) and gets his king to safety. Also, opposite side castling usually features a "pawn storm."
So, it depends. The real key is king safety. As @ArgonLights9999 said, don't castle into an attack. Watch out for (and try to launch) pawn storms when castled opposite.
Greetings!
As a 400 elo player, Is it better to always castle opposite of my opponent to prepare a pawn storm, or should I castle ASAP (mostly King side)?