One of several reasons, to keep them from being "liberated" by northern soldiers, to keep them from running away, to keep them safe and protected. They buried the family silver etc. under trees, to protect it from marauders, so putting slaves in the barn would be the equivalent. At Belle Meade in Nashville, they put the children and I've always assumed some of the slaves in the icehouse, to protect them from stray bullets during the Battle of Nashville.