A military fort is a small functioning city.
It will have a hospital of some sort for quarantine and treatment of the ill.
It may have a barber for treating minor ailments, pulling teeth, trimming hair and beards and such like.
It will have a well or spring house with abundant water. If a spring house, it may also have an adjoining cool room where food was stored chilled by using the water from the spring to cool the room. In D&D, the well or spring proper will be secured against magical attack and have a set of double doors which are guarded against invisible creatures and the like.
Water from the well or spring proper will be pumped or otherwise transported to a ready cistern which will be slightly less guarded than the well, and inspected regularly for corruption (via detect poison or the like). The cistern will supply water, and if corrupted will be emptied and replaced by water from the well. In this manner, access to the main water supply is heavily restricted.
It will have a stables for at least messenger horses, and possibly cavalry units. The stables will have a goodly supply of hay in lofts and barns. In large D&D forts, there will be a small force of aerial cavalry to at least act as scouts.
There will be a pigeon coup with messenger pigeons or some sort of trainable species that can be used to communicate with other fortresses.
In D&D, since invisible creatures are a problem, it will almost certainly have a kennel for housing at least dogs to help maintain the security of the fort.
It will have a large common room for socializing and taking meals. Firewood will need to be plentifully supplied if the air is chill.
It will have a large kitchen for preparing meals. The kitchen will need a storehouse for coal or firewood. The cook is a professional, and while his assistants may sleep in the kitchen at night, he'll demand his own quarters.
The Kitchen will be adjacent to a large supply house, including larders and pantries, overseen by the fort's quartermaster who is in charge of seeing to the fort's logistic needs, and protecting the fort's necessities from sabotage or theft. He'll probably keep the keys to much of the internal areas of the fort, and have a separate office and quarters. If the fort is in an inhabited region, he'll also oversea the protection of the fort's strongbox, from which the fort purchases its supplies, which likely has its own separate vault to protect it.
The fort is likely to have its own stockyard maintaining chickens and pigs for a ready supply of fresh meat. If the fort is large enough, this may warrant a smokehouse as well.
It will need a laundry or scullery for cleaning. If civilians are employed for this purpose, which is typical, they will need separate quarters. Indeed, on the subject of civilians, it's not at all unusual before the modern period for important people, including such knights present at the fort, to want their own servants attending them and for their to be a large body of semi-professional civilian 'camp followers' that do all the work needed to keep the camp running and attend to various sundry needs. (Including the earthy needs of young men worldwide. It's worth noting that both when occupied by the Germans and when occupied by the Americans, the first thing French mayors tried to do was organize and set up brothels so as to reduce the random rapes that are to be otherwise expected. So however strange it may seem to modern eyes used to fully professional armies, your fort may well have a brothel.)
It will have a smith for repairing tools and weapons. The smith will likewise need a storehouse for coal or charcoal. He's a professional so he expects to have his own living quarters.
It will have an armorer for maintaining armor. The armorer will need a storehouse for coal, charcoal, vinegar, sand, vegetable oil, cured hides, wire, and all the other stuff an armorer needs to function. He's a professional so he expects to have his own living quarters.
It will have a fletcher for manufacturing arrows. He's a professional so he expects to have his own living quarters.
It will have an engineer for maintaining the forts anti-siege weapons and overseeing the training in their use. As with late medieval and early modern fortresses, D&D fortresses can't hope to survive a siege passively, and must maintain heavy weapons to counter whatever trebuchets, catapults, and monsters an enemy might array against them. The engineer will have a workshop, storage, and living quarters. He may rate as high as a Wizard in terms of professional comforts. Along those lines, the fort will have various mounts for anti-siege weapons preferably higher up in the fortress so that they can outrange any siege weapon of similar size. Compared to real world anti-siege weapons, D&D anti-siege weapons will need to be more mobile and so will have provisions for training the weapon relatively quickly that otherwise wouldn't be necessary until the 20th century. This is to deal with moving threats like giants, manticores, dragons, and the like.
A larger fort might also rate a bowyer, a mason, a farrier and multiple smiths. Each of those would need a workshop and a simple quarters, and possibly storage.
It will have an armory for storing weapons securely. In D&D, it will also need access to specialized weapons such as silver arrows, bottles of burning oil, holy waters, potions and so forth to counter common monstrous threats. These will be distributed in strongboxes to avoid sabotage, some under the watch of the quartermaster and some under the watch of the base commander.
In D&D it will need a hedge wizard for maintaining the fortresses basic magical defenses and identifying or countering simple magical attacks. He'll need a shop and a storeroom, and as a professional he'll need his own quarters. He may also insist on quarters for his apprentices and a separate antechamber to his apartments, and owing to his irreplaceable value is likely to be pampered in those small regards.
It's highly unlikely that any fortress will not have a chapel consecrated to some deity of war or if not, then the chief patron of the nation that built the fort. Such a chapel will likely have the attendance of a chaplain, who like the hedge wizard will expect certain comforts appropriate to the dignity of his office.
The fort will need barracks of several sorts.
The fort will have a commander. The commander will need an office and a planning/conference room. The planning room will need to be magically secured against scrying and teleportation, and access to the entire command and control complex will be harded against invisible creatures with guards and an 'airlock' or guardroom type structure. The commander will need secure quarters and protection from magical control or influence of some sort particularly when sleeping. Wards against conjured creatures are also typical. The commander will likely have an aide with his own nearby quarters, and an assistant commander with his own secure quarters in a separate part of the fort so that the fort can avoid easy decapitating strikes.
The fort will have an intelligence officer responsible for scouting out the region about the fort for enemy movement, studying any tracks that are found, and overseeing the training of the forts sentries. In D&D, forts will need specialized sentries who help watch against surprise attack and sound alarms.
The fort will need a latrine or garderobe.
The fort will need a donjon or gaol for detaining prisoners. A typical layout would be an oubliette located at the bottom of a tower that had no high security storage. Prisoners would be chained or put in stocks within the oubliette and then deprived of light except when needed. Canques might also be used to limit prisoner freedom. Access to the oubliette would be through a trapdoor with bolts on the far side and a ladder which would be withdrawn when not needed. Since this is a fortress of war, better accommodations or apartments would not be warranted, as any important prisoners would be shipped back to facilities deeper in friendly territory as soon as practical. There might also be stocks or pillories in the yard for dealing out minor punishments. Depending on the culture, the fort might have a torture chamber for extracting information from captured prisoners.