Ill give it a shot. Lets start with, imo, "religious texts" were only ever meant to be a basic blueprint for an orderly society. Dont kill, cheat, steal, bang the neighbors wife, etc.
Then lets assume that ancient man didnt have any concept of microbes. But he is an observant creature and notices that poorly prepared pork and fowl results in buttworms (Trichinella spiralis). He doesnt know why, only that it happens with those animal groups.
So now he codifies the "unclean" nature of those animals and instructs that they should not be eaten.
Or maybe space Jesus told them directly to their faces. Dunno.