Such laws were common in the South.
The salient point, as our friend has pointed out, is that free States also had such laws, which would seem to be absurd on the face of it.
The fact is that such laws weren't about slavery so much as race. Slavery was the background, but race was on the point of the legislation.
In the South the protection of slavery was the first consideration of every law and none would be passed if they endangered it.