A gift with conditions subsequent is not a gift
Someone gave me an elephant and told me not to give it away or sell it.
What we have here is not a gift - a gift is unconditional. A gift requires three things: intent of the gifted, transfer of the property, and acceptance by the gifted. It also can’t come with “strings attached” - or conditions that apply after the gift is given. Conditions that apply before the gift (get good grades and I’ll give you an elephant) are fine, but once given it’s your elephant to do with what you will.
So a) you can refuse the gift, and b) if you accept, you can ignore any supposed conditions that come with it.
It’s also not a contract
A contract requires consideration on both sides - a quid pro quo. You got an elephant from them , what did you give or promise in return? If nothing, then there is no contract.
Now if you promised to care for the elephant and not sell it or give it away then we have a contract and you must keep your promises.
… unless it’s illegal
Private arrangements, whether gift or contract, do not allow you to break the law. If it’s illegal for you to have an elephant, then it’s illegal for you to have an elephant.
If it’s too expensive for you to keep an elephant in accordance with the law but you nevertheless contracted to do so, then you must break your contract and possibly be sued for doing so.