The alleged origin is a king who gave them as gifts, knowing they had no practical use and hoping the cost of feeding and caring for them would bankrupt the recipients.
From Thailand. Elephants are sacred there, especially white elephants. So if someone gave you a white elephant you could not refuse or get rid of it without causing offense.