iMovie and GarageBand are not necessary to the system and you may delete them at will. However, note that many other apps that come preinstalled on macOS are important to the system (even if it doesn't seem like it) and should not be deleted. As Steve Chambers commented below, though, macOS won't let you delete anything that falls into this category, assuming you aren't doing anything to get around that.
If your Mac was purchased after October 1, 2013, you can re-download the iLife and iWork apps (pictured below) for free at any time from the Mac App Store. Also, regardless of that, if you see them in the Purchased tab of the Mac App Store, that means you do have a “license” for them and can download them at any time.