Short answer. No, you keep it. Article 873 says that impossible conditions, and those contrary to law or good customs, are considered as not imposed and cannot prejudice the heir — even if the testator directed otherwise. The bad condition is struck out and you take the inheritance free of it.
What the law says
Impossible conditions and those contrary to law or good customs shall be considered as not imposed and shall in no manner prejudice the heir, even if the testator should otherwise provide.
Civil Code, Article 873 — Impossible and Unlawful Conditions. Read the full provision →
What Article 873 provides
Article 873 provides that impossible conditions and those contrary to law or good customs shall be considered as not imposed and shall in no manner prejudice the heir, even if the testator should otherwise provide. This treats a defective condition in a will very differently from the way ordinary contracts handle one. In a contract, an impossible or illegal condition can bring down the whole obligation. In a will, the law leans towards saving the gift: it removes the bad condition and lets the inheritance stand, so that a testator's faulty condition does not cost an heir what was meant for him.
The two kinds of condition it covers
The article reaches two categories. An impossible condition is one that cannot be done — physically, like touching the sky, or legally, like requiring an act the law will not permit. A condition contrary to law or good customs is one that asks for something wrongful or offensive to public morals — to commit a crime, to abandon a spouse, to change or keep a religion as the price of the gift. Both are treated the same way: struck out. The testator cannot use the will to command what the law forbids or to buy conduct the law disapproves of, and the attempt simply fails.
'Considered as not imposed' — and the gift survives
The operative phrase is that the condition is considered as not imposed and shall in no manner prejudice the heir. So the heir does not have to perform the impossible or unlawful thing, and does not lose the gift for failing to. The condition is deleted and the institution is read as if it were unconditional. The closing words — even if the testator should otherwise provide — shut the obvious loophole: a testator cannot save his condition by adding that the heir forfeits if the condition is not met. That forfeiture clause is disregarded along with the condition itself.
One important boundary
Do not stretch this too far. Article 873 rescues the heir from a bad condition; it does not turn every unwelcome or merely difficult term into one that can be ignored. A condition that is lawful, possible and moral remains binding, however inconvenient, and must be complied with to take a gift out of the free portion that carries it. The question is always the nature of the condition — impossible, or contrary to law or good customs — not whether the heir would rather not perform it. If there is genuine doubt which side of that line a condition falls, settle it before acting on the will.