In the case of the tribes in Madagascar, maybe it’s symbolic? Like with long nails in those conditions, parasites and bacteria could collect under them which results in sickness which could be interpreted as the devil🤔
Long nails aren’t very hygienic. They trap a lot of dirt which could have dangerous things in it and the best way that the ancient people could describe it was the Devil.