What could cause a shower to give warm water for a few seconds, then only cold water?
Your water supplies may be pre-mixing. That is, mixing cold and hot water even when no faucet is on. This may happen if you have any fixture where hot and cold water handles/valves are left on but a third valve that is used to regulate flow and is shut off. You, or a previous owner, might have made this configuration so that the temperature never has to be adjusted at that fixture, for example. The hot and cold water may be mixing in the short length of pipe/faucet behind the third valve. This reservoir of mixed water then begins to extend out into the supply pipes. If so, you might get this pre-mixed, warmish water from a second fixture nearby, even when you only turn on the cold water at this second fixture. After a few seconds, the pre-mixed water is flushed out of the cold water supply pipe and pure cold water comes out the faucet. This may explain the initial burst of warm water from the shower. 

Edit: To (hopefully) illustrate the above pre-mixing scenario, imagine this. You have hot and cold supply pipes leading to your bathroom. Each junction, one leg going to your tub+shower and one going to your sink (ignore the toilet for a minute). The sink's hot supply goes to the hot faucet handle. The sink's cold supply goes to the cold faucet handle. Nothing hinky there. Now imagine the hot and cold supply goes to a tub with its own hot and cold faucet handles. One old tub fixture I've seen had two additional valves (in addition to the two from the faucet handles). One to control the flow of the tub faucet and another to control the flow of a shower head. Now let's say both the tub and shower flow valves are turned off so no water is flowing but the cold and hot water faucet handles/valves are turned on and left in position so that the mix/temperature doesn't have to be adjusted. What may happen in this case is that the hot and cold water supplies become connected and open to one another in that little length of pipe that sits between the hot/cold faucet handles and the tub+shower valves. So the hot water slowly bleeds into the cold supply and vice versa. After some time the warmish water in the cold water supply spreads back to the supply's junction and then further down the pipes toward the sink faucet. Then when you turn on the sink's cold water the first burst is warm rather than cold, all because there is a wonky fixture configuration somewhere nearby that opens the cold and warm supplies to one another. Now this particular configuration is old and probably very rare (and poorly designed... and don't wrack your brain too much trying to visualize this faucet/valve figure, just the idea of pre-mixing) and it doesn't describe your configuration but I mention it just as a possible clue to follow. Check nearby fixtures and appliances (laundry?) that may be either misconfigured in such a way to broken and thus pre-mixing the hot and cold water even when the fixture/appliance is not on/running.

As for why the shower ultimately produces cold water when the handle is turned to hot, it almost sounds like the hot water supply is connected to the cold stem on the back of the shower flow/temp adjustment valve, and the cold supply connected to the hot stem. Try leaving the shower valve adjusted to cold for a while and see if the water gets warmer. Also verify that the connections at the back of the valve are not reversed.

Also, try to collect more details on when the hot water pipe gets warm and gets cold. If the hot water pipe between the shower faucet/valve and the nearest junction is ever getting hot that suggests that hot water is actually flowing through the faucet. If it gets cold when the faucet is on that suggests that the cold water pressure is overwhelming the hot and pushing its way through the shower mixer into the hot supply pipe.

Hope some of this helps.