Freehub comes free from wheel with cassette attached
You usually can't remove the freehub body on most hubs by hand, as is probably obvious. However, on at least some hubs, the freehub body does slide right off. Mountain Bike Rider mentions this about DT Swiss star ratchet hubs in general, and I am able to do this on a DT Swiss 370 hub (a lower-end hub with pawls). Consider that while you are riding, the hub is under some compressive force from the thru axle or quick release. The freehub should be unable to just back off out of the hub.