It's not illegal, per se, but it is considered a joint asset. That means that if the other party pursues a property settlement, that money will be considered as part of the joint asset pool that needs to be divided and the other party will be entitled to a portion of it, whether it remains in the joint account or not.
It's not wise to meddle with shared assets until a property settlement is agreed to. If you deny the other party of their financial resources, it's usually considered an act of domestic violence.