The way the 4WD light system works is via contacts on the shift motor on the transfer case.
In a 2004 Ranger when you select 4high it activates the 4x4 module Relays which powers the shift motor, the motor turns the shifter shaft and also a contact plate, while turning, the contact plate opens and closes connections, until the 4High connection is reached.
These are physical contacts not electronic sensors, metal to metal contact.
If the contact wheel should be on the edge of the contact the light may come on and then go off, which reads like what is happening.
By going to 4Low and then back to 4high the contact wheel may be stopping more in the center of the contact, so light stays on.
This thread has good pictures of the contact wheel: How to: Rebuild 4X4 Shift Motor | Ford Explorer and Ford Ranger Forums - Serious Explorations
And here, this one shows the slotted and marked cover: http://www.therangerstation.com/tech...shiftmotor.htm
You can see there are 3 screws that hold the cover for the contact plate on, these may be slotted so you can adjust the contact points inside a bit by loosening and rotating cover a bit.
And the whole motor assembly can usually be rotated a bit to match correct shift shaft points so transfer case is fully in 2WD, 4WD high, or 4WD low.
And it could be the contacts inside for 4 high are dirty or corroded