It’s essentially impossible that Fermat knew of Wiles’s solution. It took 350 years to develop the math necessary for it. There has been a reasonably plausible pseudo-solution proposed that may be what Fermat was thinking or and is consistent with the state of math in Fermat’s time. In calling it a pseudo-solution, I mean that it doesn’t quite work, but you can easily imagine Fermat mistakenly thinking that it does work.