This seems like an obvious yes to me, but I've searched the internet and can't seem to find a solid verification that this actually happened? Can anyone point me in the right direction, perhaps to some trusted sources? Thanks in advance.
Yes, assuming they had forewarning and the commander of the castle allowed it, two big ifs.
One of the saddest incidents in medieval warfare occurred during the 1204-1205 siege of Chateau Gaillard in Normandy. The townspeople of Les Andelys, located beneath the castle by the riverside, sought refuge within the fortress's walls. After several months without relief, the castle's commander decided to expel all non-military people from the post. The King of France, Philip II, refused to allow them through his siege lines, presumably thinking that they would be forced back within the castle to continue eating up precious supplies. But the garrison would not open the gates to them, and they spent some weeks trapped between the two armies, starving and freezing, before Philip relented and allowed them to pass through his lines.
Generally yes, but it would not be automatic. For example, the city of Straznice in Moravia was fortified with a castle and during the invasion and breaching up the wall, population sought a safety in the castle. However, the population had a strained relationship with the landlord and during the invasion, they were refused the entry. Enraged people in a desperation and revenge set a fire to the castle as their city burned.
In 1666 during Ottoman invasion of Moravia a castle Brumov was a fort controlling a flow of people between the kingdom of Hungary and Moravia in a Vlara pass. Several hundred Wallachian were guarding the mountain pass when they were overwhelmed and survivors sought a refuge in the castle. The landlord refused to open the gate and about 200 military died on top of many civilians.
In wars with Hungary, Cumman and Mongol rides, the castles in Moravia served as a protection for a local population. Most of these wars were quick without long sieges so there was not much a concern for starving out the population. Hussite wars were known for long sieges and sometimes the landlords expelled peasants to face a certain death from the enemy.