Follow/Wander AI disabled with creatures spawned/tamed naturally in caves

Does anyone know where is the line located that prevents tamed creatures to follow you in caves? I’m having some problem with bringing tamed Titanoboas out of the cave as they don’t follow you, not even after you bring them to surface by riding.

To explain it more clearly: Titanoboas spawned with console have proper and fully working AI. Titanoboas spawned naturally by the game in caves have the Follow/Wander AI disabled.