Sure they can. Military personnel give up all sorts of rights when they sign their contract of enlistment. Non-disclosure, non-compete clauses are common in contracts. The list goes on. As long as the contract is voluntary, there's nothing wrong with it.
Name a right you give up by enlisting, keeping in mind what the definition of a right is.