I'll swap Phoenix and Edgeworth in my theory.
Edgeworth is the culprit. Phoenix is the accomplice.
Edgeworth lets Franziska out of the study, locks the door again, Franziska hides in right bathroom, Edgeworth makes her open the door and kills her.
Edgeworth being knocked out by Larry never happened.
When Payne and Alfred were in the study and discovered Franziska was gone, Phoenix ran into the right hallway, while Edgeworth ran into the left hallway. They exchanged their keys during a brief meeting.
Phoenix entered the library, and pretended to be an unconscious Edgeworth.
As for the clue for such a disguise - well, Phoenix was seen wearing his hat all the time (even indoors, which is strange enough to be notable, and therefore can constitute a visual clue), so it's possible he prepared a haircut identical to Edgeworth and was trying to hide it. As for Edgeworth's red coat - Edgeworth could give it to Phoenix also along with the key, no need for extra clothes.
Payne found Edgeworth lying on the ground, and it's plausible he couldn't take a look at his face depending on the position (and he was distracted by Larry soon afterwards).
During all this, Edgeworth had time to barricade Klavier (or Phoenix barricaded him previously).
After this point, the events are identical to my previous theory, but with Phoenix and Edgeworth's positions switched.
And they would have the necessary keys to lock Payne in the study.
Now, about Phoenix's purple statements.
I was living it up with a grape juice stash in Larry's wine cellar I found before the party kicked off.
Him drinking some juice while he still was in the cellar doesn't contradict anything.
I didn't notice anyone enter the wine cellar while I was guarding it.
It's just a true statement.
I was guarding the door, but I must have drank too much grape juice, because I passed out.
Alright, here I'll have to interpret just a little liberally: if we take the first half of the sentence and the second half of the sentence on their own, I say there is no problem: there was indeed a period of time Phoenix was indeed guarding the door; him getting passed out also really happened, but it happened after Payne was locked in the study.
When I woke up, the key to the dining room was on my personage.
Nothing wrong with it.
In case my interpretation of Phoenix's statement is flawed, there is an alternative:
Phoenix did just guard the door, drink juice and pass out. Then while Alfred and Payne were in the study, Edgeworth ran through the central hallway to wine cellar, swapped keys, woke Phoenix up with a slap or something, gave him the coat. And after that Phoenix quickly ran to the library.
That way, there shouldn't be any problem with Phoenix's testimony at all, other than omission.