Let's suppose a CFI can no longer qualify for a 1st or 2nd class physical, or maybe her/his 2nd class physical was 18 months ago. Can she/he still give required instruction and endorsements as long as they don't charge for their time and are not paid for it in any other way?
A CFI with a third class medical can provide any kind of instruction that they are qualified for (and be compensated for it), per 14 CFR 61.23(a)(3)(iv) and (v). The FAA's position in these scenarios is that you're being compensated for the transference of knowledge, not the operation of the aircraft.
For completeness, A CFI can provide instruction WITHOUT a medical if they are not flying PIC or acting as a required crew member. In this scenario training can be provided for certain additional ratings (e.g. commercial) or flight reviews AS LONG AS the student can PIC during that flight AND the CFI is NOT a required crew member (i.e. safety pilot for insturment training). Additionally, the FAA has made a legal interpretation that a CFI can provide instruction to a pilot that is not current to carry passengers, as long as all other requirements for the student to be PIC can be met.