Under the assumption that I'm far enough out that I need to hike out on my own, and that I have someone who can help... what is the best way to immobilize a dislocated shoulder for a long hike out of the woods (5+ miles)?
First do a proper assessment and determine that it's actually a dislocation and not another problem or that there isn't also another injury in addition to the dislocation. This requires the proper training which is beyond the scope of this medium. This is not a substitute for proper training.
So you've done the assessment and there are no life-threatening issues or other injuries to complicate treatment of the dislocation. If possible, it needs to be reduced, which means you want to get the shoulder back in its proper place. There are several techniques for this, but the primary one being taught in Wilderness First Aid classes is called the Stimson maneuver:
This is simply a summary and not an exhaustive step-by-step. I skipped many things that should be done as part of any proper patient assessment and treatment. Any first-time dislocations should evac because of possible complications. If it is not a first time then do a proper assessment and determine whether it's needed based on information from the patient.
Again I can not emphasize enough that this is not a substitute for proper training. It's highly possible for the mechanism of injury (MOI) that caused the dislocation to have cause other injuries that need treatment, some of which could be life threatening. That's where the proper assessment is key.
Sources: My own training through both NOLS WMI and ARC is the primary resource I pulled from. The links referenced outline the the same basic procedure with slight variations since my training is intended for a backcountry environment with no immediate access to primary medical care.
You don't want to immobilize a dislocated shoulder. You really need to fix it. Even if held at just the right angle and not being jostled around, a dislocated shoulder hurts. After a while the muscles will tighten, then start spasming periodically. Then it really hurts and it becomes much more difficult to get it back in.
There are some dangers in getting a shoulder popped back in by a non-expert, but the downsides and practical near impossibility of hiking out any distance with a dislocated shoulder outweigh them.
Once the shoulder is popped back in, the person will immediately feel better. It will be sore and will be in danger of popping out again easily, but it won't hurt anymore. Now is the time to arrange some sort of sling to keep the lower arm roughly accross the belly and tied down so that it isn't used, even if accidentally. Little things we normaly can take for granted can pop it out again, but not when the lower arm is held accross the belly.