I love a good regs debate.
Before I start let me make it clear that Bob is correct. I was perhaps not complete in my answer so allow me to pose a scenario to clarify.
let's set some ground rules so we have a common frame of reference.
First, let's all assume that Pilot A owns some sort of aircraft that requires the airman, while exercising the privileges of their pilot certificate in that aircraft, to hold a medical certificate.
Second, let's all assume that Pilot B is current and qualified in every way shape and form to exercise PIC authority in the same aircraft.
Third, lets all assume that both pilots have, and are conducting operations requiring a Private Pilot Certificate
Here we go.
Pilot A is appropriately certificated and current but due to life getting in the way is just not able to make it to his AME in time and his medical lapsed.
Pilot A calls Pilot B and asks him to come along on a flight because Pilot A's medical has expired and he is not legal to fly.
FAR 61.2.a.5 says in part that you can't exercise the privileges of your medical certificate if it has expired.
FAR 61.23.a.3(i) says you must have a third class medical certificate in order to exercise the privileges of a Private Pilot certificate.
FAR 1. Section 1, Definitions. Pilot in Command is defined as;
1. The person who has final authority etc.
2. Has been designated as the PIC before or during the flight.
3. Holds an appropriate category, class, and type rating etc.
Question. Who is Pilot in Command?
I say (and I think we all would agree) that in this instance Pilot B is the PIC. Pilot A cannot exercise the privileges of his medical certificate because it has expired. The operation being conducted requires a Private Pilot certificate and in order to exercise those privileges requires a medical which is a round about way of saying Pilot A can't be PIC because he doesn't have a medical.
How to log it.
Here is where, as Bob noted, it gets really muddy
FAR 61.51.e is where this is described.
Bob correctly points out that a Private Pilot can only log PIC time when;
1. He is the sole manipulator of the controls in an aircraft he is rated for.
2. He is the sole occupant of the aircraft
3. He acts as PIC in an aircraft that requires more than one pilot by certification or regulation.
Situations 2 and 3 don't count since Pilot B was not the sole occupant and the aircraft type or operation did not require more than one pilot so that leaves us with sole manipulator.
Pilot B was the PIC for the entire flight but could only log the time he manipulated the controls. I do stand by my original answer that it doesn't matter if Pilot B was in the left seat or right seat (let's leave out the Bonanza throw over yoke debate for another thread), Pilot B was PIC.