As long as the reason is not illegal (i.e., based on a protected class or action), it is typically legal. However, some employment contracts come with protections that prevent employers from firing their employees after giving notice.