You can stow a weapon as part of your one 'interact with object' action during your turn. You can always move, stow a weapon, and then take an action (such as cast a spell). You just can't redraw the weapon to have it in your hand at the end of your turn. However, next turn you could then draw the weapon and still have all action. About the only downside is that you wouldn't be able to take a reaction attack if someone provokes an attack by moving out of your reach.

Further, you don't necessarily have your hands free if the spell only has a verbal component. In addition, if the spell can be cast as a bonus action... you could put your sword away, cast (bonus action), and draw your sword (using your action).