Barring some abnormally lenient local code revision, the only way to "correctly" fix this is to run suitable new conduit to the wellhead, and relocate the wires (or put new wires) inside it.
I've seen some examples of code revisions that relax the rules for what's an acceptable conduit (outside the building/house) such as permitting Schedule 40 where normally 80 would be required, and permitting poly water pipe to be used as conduit (rather than properly marked for use as conduit poly conduit) but not "no conduit at all" without the cable being rated for direct burial.
Inside the well, the well casing itself serves as a conduit, and well wiring is permitted to be otherwise unjacketed wires. Outside the well, that does not apply.
You could improve the optics by retrofitting conduit (and junction boxes, or "handholes" where buried) to as far as you're willing to dig past the point where the wiring goes underground, but that's not really getting it done "correctly" as you ask.
Correctly is facing that you have inherited a code violation that should never have passed inspection (perhaps was never inspected) and it's going to be an unreasonable hassle to fix correctly. Be sure that well power is turned off at the breaker when digging, as there may be other naked buried junctions along the way. I'm also fairly sure that you need a grounding wire if trying to be "correct" - not just the two hots.