The idea of JWST was conceived around 1990, when Hubble was freshly flown into space and people started thinking about its successor. Development in earnest started in 1996 and JWST should have been ready to launch in 2007. This date was pushed back many, many times. (Much like with construction of nuclear power plants - megaengineering projects tend to suffer from this kind of slip-ups, cost overruns and delays.)
This means that the definite launch arrangements were done before SpaceX was the giant it is today. Space Shuttle was discontinued, so the most reliable rocket of that time simply won. This is no ordinary payload and you really do not want to lose it to launcher failure.
Then one partial failure on 25 January 2018, and another consecutive stretch of successful launches, including today.
>"Faced with a grim record of 4 failures from just 14 Ariane 5 launches, some observers were starting to ask if Europe's 25-year-old rocket programme is more trouble than it's worth."
>"Although developed primarily for the commercial market, a new class of heavy-lifter rockets will also be used to launch the next generation of deep-space research probes, such as the planned James Webb space telescope, Southwood says."
https://www.nature.com/articles/420723a ("ESA weighs up future after Ariane explosion") [2002]
Falcon Heavy does have enough capacity, but:
1. It was not really available for bookings when the JWST mission was planned and
2. even if NASA could choose again today, Ariane 5 has a track record of 106 successes out of 111 launches (107 out of 112 now I guess) and Falcon Heavy is still relatively untested with only 3 launches (all of which were successful, but still only 3). For something super critical you might want to go with old but dependable technology over the newest hotness.