Of course roaming legendaries can sleepwalk ._. if humans can do it in real life, why not imaginary creatures in a game.
Anyway it wasn't always like this;
> Status ailments that prevent the Pokémon from using moves like sleep, paralysis, and infatuation only prevent the Pokémon from fleeing in Generation II.
Due to me not having access to the inner workings of Gamefreak and also not having access to whatever drugs they're taking when they're coding the games, the typical answer is probably the only answer I can think of to answer this question. I would have said Gamefreak were being lazy bums and couldn't be bothered to code it so sleep blocked fleeing but since it occured in Gen II and they changed it... >.> that theory's out the window. Maybe they're just overactive? :3
Though they might have just done it to make more difficult for the people trying to get the legendaries.