Your hospitals are one of the most critical buildings in your city when it comes to battle. You have your main hospital, which you built during the tutorial, and there are 16 other spots where hospitals can be built in the fields surrounding your cities. The hospital is so important because without hospital space all troops wounded will be dead, but more important when defending against an attack if your hospital space exceeds the number of troops you have no troops will die. Wounded troops are a lot cheaper to heal than dead troops are to retrain and much faster too.
When attacking your troops have a 60% chance of being sent to the hospital instead of dying, once that hospital space is full all remaining troops wounded will also die.
Also note, since weaker troops are weaker they will fill your hospitals first. So for example, let’s say you have 30,000 troops and 20,0000 hospital beds. Of those troops 20,000 are Veteran and 10,000 are Elite. You are attacked by a much bigger player and all your troops are beaten. Your Veteran troops, the weaker and cheaper to train ones, will survive, your Elite troops will die because the Veteran fill the hospital first.
To check your Wounded Limit versus Total Troops check your Military grounds. Wounded limit is in the upper right of the dialog.
Going Over Your Hospital Limit
You can go over your hospital limit and still not lose troops defending by employing the Shelter to hide any troops over your limit. This can be dangerous because it means you have to pay close attention to your game and where your troops are. For example one strategy employed by higher level players is to keep a number of light bowmen to gather with. Since bowmen have good gathering stats and Light troops are very cheap and fast to heal this means not having to worry about being attacked on a resource. However if those Light troops exceed their hospital limit it does always mean being aware of how many army they have exposed at any given time and especially when offline. Your Shelter capacity is equal to your single army deployment limit, which is governed by your castle level.
Also late game you are probably going to exceed your hospital limit in troops. With a maximum of 17 hospitals that is 680,000 maximum spaces (I am not sure if you have to keep one mint after all the buildings that require it as a prerequisite are built, if so that is 16 maximum hospitals or 640,000 troops)