Castling itself (as a single move) is a 17th century balance update. Before that it was done as separate moves. But the only reason castling became a thing was because the Queen and Bishop were buffed in the 15th century allowing them to threaten more spaces. This made it more advantageous to fortify the king’s position than to have him flee.