A trust can have any terms or conditions in it that the person establishing the trust wants: a trust could say that you forfeit the money/assets by committing a felony, or by getting married (or not getting married), or by moving out of town, by refusing to work in a certain career, etc. So if the trust instrument or paperwork says this, it is legal.