Formal verification is obviously better if you can do it. But it's still really really difficult, and plenty of software simply can't be formally verified. Even in hardware where the problem is a lot easier we've only recently got the technology to formally verify a lot of things, and plenty of things are still out of reach.
And even if you do formally verify some software it doesn't guarantee it is free of bugs.
Whether it's a neural network inside or not is completely irrelevant. That's why it's called "black box".
You make a black box test on several thousands (sometimes only hundreds) patients, and if patients who received the drug perform better the patients who received the placebo, then the drug is usually accepted for commercialization.
Yet one isolated patient may be subject to several comorbidities, her environment could be weird, she could ingest other drugs (or coffee, OTC vitamins or even pomelo) without having declared it. In a recent past women were not part of clinical trials because being pregnant makes them very "non-standard'.
Secondly, even after the product hits the market the company is still responsible for tracking any possible adverse effects. They have a hotline where a patient or doctor can report it, and every single employee or contractor (including receptionists, cleaning staff, etc.) is taught to report such events through proper internal channels if they accidentaly learn about them.
I don't know where you get that, most clinical trials last 26 weeks, even in phase III.
and about "more thorough than you imagine" no, most are subcontracted to CROs and the way clinical trials are conducted is messy.
Below is story from the POV of a PI.
But similarly many patients complain about the way they are treated in visits and the lack of interest of the nurse/doctor who receive them.
https://milkyeggs.com/biology/why-are-clinical-trials-so-exp...
Clinical trials also have strict ethical oversight and are opt-in. If clinical trials were like Teslas, we'd yeet drugs into mailboxes and see what happened.