Ordinarily I'd go with the idea of replacing the headphone port as the first step (after, of course, trying a different headset as suggested by @fixerofstuff), but the part about it working momentarily when opening and closing the screen makes me rethink that.
Unfortunately, I don't know enough about the internals of the DSi to be able to guess what cable is causing the problem, but it seems like that would be an avenue worth investigating. If it was me, I'd try removing the lower case, leaving the cables and wires connected and turn it on. With headphones plugged in, try flexing all the wires to see if one in particular causes the issue. It could be as simple as a loose plug somewhere, or it could be a damaged flex cable, possibly; those are the usual culprits when opening up a device like a DSi or even a laptop causes problems at certain angles.
Just to cover all the bases, if it does come down to the headphone jack itself, it can be replaced without having to buy a new motherboard, although it would take some moderate soldering skills. From what I can see it should be doable with just a soldering iron and not require anything fancy like a hot air station. If you did want to do that, you'd use the motherboard replacement guide to pull the motherboard first.
Nintendo DSi Motherboard Replacement - iFixit Repair Guide
The part itself can be found online; I didn't see where iFixit sells it myself, but I didn't spend a lot of time looking. Here's an example of one I found; this isn't a recommendation, just one of the first ones I came across.
Headphone port for DSi 3.5mm - ZedLabz
Good luck, and be sure to come back and let us know what you find. Whether you manage to fix it or not, your experience could help the next person who comes along with a similar problem.
crwdns2934105:0crwdne2934105:0
crwdns2934113:0crwdne2934113:0
crwdns2915270:0crwdne2915270:0
crwdns2889612:0crwdne2889612:0
1