Freelancing lets you build up a portfolio of work, build relationships with people who can give you work or referrals, solve problems in different domains with different tech stacks, and test yourself as a sole proprietor. It helped me get a lot of experience in a short time.
Times change and these days I would only recommend freelancing for people starting their careers or for people who need some income quick. There are a few issues: you usually won't be trusted to work on mission critical parts of the business, clients care less about quality than you do, sometimes you have to take work that's incompatible with your career goals, and price-sensitive clients can be difficult to deal with when it comes to payment. Looking back, I'd likely do it again, though I'd charge more and be more selective about projects.