Is there a restriction on who can inherit your wealth? For example, I doubt that you can donate money to the Taliban if you're a U.S. citizen, so I am wondering if the American laws specify what those restrictions are or if it's up to the judge to decide if a will is valid or not. Can you make sure that a foreign entity, or a citizen from a different country inherit your money? Assume that the question only applies for Americans.
Generally a person can leave money to any person or organization that the testator pleases. In some US states, a minimum portion must be left to family (spouse and/or children). Aside from that, there is no requirement and no exclusions.
US law prohibits gifts (and other support) to a few specific organizations which the government has officially listed as terrorist, and
I suspect the Taliban is one of these. Gifts by will would be covered by this law just as gifts from a living person. But if a living person in the US can lawfully make a gift to an organization, a similar gift may be left by will. Even if a particular bequest was unlawful, that would not make the will as a whole invalid.
Edit: It seems that the Afghan Taliban is not on the list of terrorist organizations maintained by the US, and so there would be no bar to a US citizen leaving money to that group. There would be to groups actually on the list. The general principle above holds.
TL; DNR: Americans can bequeath money to the Afghan Taliban.
Yes, there are many legal restrictions on what one can do with one's wealth.
First, many states give a surviving spouse and children rights in the estate. These rights vary dramatically. They range from the right of survivors to a "reasonable" family allowance to the right of the surviving spouse to choose whether to take a fixed portion of the estate rather than what is provided in the will. In community property states, the surviving spouse is entitled to his/her 1/2 of all community property, unless otherwise agreed.
CAVEAT: In many states, these laws apply only to the portion of the estate that passes through probate; they do not cover property held in trusts.
Second, bequests are also subject to 18 U.S. Code § 2339B. This statute makes it illegal for anyone in the US, or subject to the jurisdiction of the US, to provide "material support or resources to designated foreign terrorist organizations."
The State Department lists the "designated foreign terrorist organizations" here. This list does not include the Afghan Taliban. The reason, as the Voice of America says, is "political expedience" -- if the Afghan Taliban were on the list, it would complicate diplomatic contacts and negotiations.
Added: The Taliban may not be listed as a designated foreign terrorist organization, but it IS on the list of the U.S. Treasury's Specially Designated Nationals. Executive Order 13224 says that for any entity on the list,
...any transaction or dealing by U.S. persons or within the United States in property or interests in property blocked pursuant to the Order is prohibited, including but not limited to the making or receiving of any contribution of funds, goods, or services to or for the benefit of individuals or entities designated under the Order.
Civil and criminal penalties may be assessed for violations.
Want to know more? For those who want to know more about the rights of spouses and children, there are accessible discussions here, here and (for community property states) here. The rights in every state are summarized here.
The "Rule Against Perpetuities" limits your ability to create future interests, that don't vest until far in the future. Barring a sudden leap in technology, you (probably) cannot leave your estate to "your first descendant born on Mars" or anything like that.
The specifics vary from jurisdiction to jurisdiction--and are notoriously tricky. The classic version by John Chipman Gray is that
"No interest is good unless it must vest, if at all, not later than twenty-one years after some life in being at the creation of the interest."
In other words, you can leave a bequest to someone who is living or use them as a "reference" to leave it to someone who will be living at the time. Wellington Burt is perhaps the craziest example of this: he died in 1919, stipulating that most of his estate was to be distributed 21 years after the death of his last living (at the time of drafting) grandchild. This happened in 2010 and one of the recipents was born 73 years after he died!
Some jurisdictions have subsequently opted for simpler rules: 90 years from the drafting date, for example, is relatively common.