Mark establishes Capernaum as Jesus' base of operations before telling us (3:20) he "came home". Then (3:31) his family tries to get to him through the (obviously, local) crowd. And Jesus says, "Who is my mother?..." (FYI - in harmonized chronologies, no other Gospel event occurs between these two points.) Now, to conisder this historically...
This is one year into Jesus' ministry, just after appointing the twelve, and he'd already had a year of experience visiting Capernaum, where he'd moved the whole family (except for his grown, married sisters, who stayed in Nazareth). At this point, Jesus had probably begun to see signs of the unrepentance that eventually got Capernaum put onto his 'denunciation list'. But whether Jesus was predicting this already or just preparing himself for the likelihood of it - either way - he must have been concerned that anti-repentant townspeople could resent Him in their own secret shame and take it out on his family in various ways, with social hostility being perhaps the least of his potential concerns.
Putting all that together, it seems Jesus was actually protecting Mary by so clearly and publicly distancing himself from the family in their new home town. This doesn't change the fact that his words were true and the point he made absolutely remains valid in its own right, but it does take some of the coldness and sting out of his words, at least for us, in retrospect.
(***Is that what Mark intended us to think? Probably not. But if we take the event to be truly historical, our considerations are not necessarily bound by points Mark was trying to make in his particular composition. We are reconstructing events for their own sake.***)