I castled why did I lose


I just looked at your game. I think it's because your King can't move anywhere. It's in check and can't get out of it. This type of loss has happened to me and it's frustrating.Â
Â

Had the white pawn on h2 been on h3 you could've moved your King out of check. At this point in the game you need an escape route for your King.Â
Â
It's called a back rank checkmate. Was it your first? Always be aware of the back rank situation if files are open. It's pretty easy to spot the threat once you know what to look for. In this case your bishop was blocking your rook from defending so your back rank was weak. Bb2 would have allowed your rook to defend along the rank or h3 would have created an escape square (luft) for the king. No need to waist a move on h3 unless you see a threat or want to lift your rooks, as it weakens the pawns protecting your king. There are many tactics for exploiting a weak back rank. If a single rook is defending the rank, this can be exploited if it becomes overloaded with multiple responsibilities.
Rules of thumb are relatively decent for when you aren't sure what to do (such as castling is better than leaving your king in the center) but such guidelines do not work in every situation.
Â
When you are starting it is usually okay to pay attention to them but stronger players better understand the reasons behind the guidelines and thus know when to ignore them. When the center is locked I may play Kd2 instead of castling and connect my rooks to launch a king-side pawn storm (violating the guideline to seek king safety by castling).
Â
In an unusual pawn position I have deliberately traded rooks to reach a K+B+6P vs K+B+6P position where my light-squared bishop was able to prevail over my opponent's dark-squared bishop (violating the guideline that says such ending are virtually always draws). Pretty much every sacrifice violates the guideline against losing material and a good sacrifices violates it successfully.
Â
Then there are the guidelines that occasionally compete against each other. As an example, after 1 d4 Nh6 White has the option to play Bxh6 that violates the guideline that having the bishop pair is better than having the knight pair, but which follows the guideline that saddling your opponent with doubled & isolated pawns is a good thing to do (while also smashing open the kingside). I'll play 2 Bxh6 instantly and continue knowing that if my opponent survives the middle game and all the pieces are traded off then I am favored to win the endgame. In a post-mortem after one game my opponent (about 500 points lower rated) said that he felt good because we were materially even to about move 30 and I pointed out that after 6 Nh3 BxN 7 gxh3 White's game was already definitely inferior with a shattered pawn structure (probably lost against proper play) and all I had to do was slowly tighten the pressure.
Â
To recap
1) learn the guidelines (sounds like you are doing that)
2) understand the reasons for the guidelines (that can take a while)
3) learn when the guideline can be violated (that will help you see ahead to threats of your opponent successfully violating guidelines)
4) a position you are comfortable with that slightly violates guidelines (or has other inferiorities) is generally better for you than a technically better position you are not comfortable with (my openings are not the greatest but even strong players at my local club that play be regularly have difficulty cracking them)
The book Bobby Fischer Teaches Chess is basically everything the beginner needs to learn about back rank checkmates. I would start there. The back rank never ceases to be an important theme, no matter how much you improve as a chess player, and it's incredibly useful for the novice.