When turning on a hot water tap why does the water begin to warm up but then suddenly go cold before it begins to get hot again?

If you do not have a separate hot water heater, it is possible that you have a mixing valve on your boiler and if it is open, it creates an imbalance in the system. So while you are taking a shower and someone turns on the hot water in another area of the house, the pressure on the cold side increases an follows the direction of least resistance and mixes more cold water with the hot than it normally would. As a result, the water in your shower get colder. This can happen even if the mixing valve is completely closed. In the same way, if someone turns on the cold water somewhere else while you are taking a shower set just the way you like it, the water could all of a sudden become very hot. Mixing valves were the answer years ago to mix cold water with super hot water coming from the boiler. They never work very well. So, the best way to avoid temperature fluctuations is to replace faucet with built in temperature adjusting controls. Set the temperature you want and if the pressure, hot or cold drops, the faucet will automatically adjust and the temperature to your setting. Your water pipes might come in contact or are very close to a hot water heat pipe or a heating duct. It may be in the same joist bay. When you do not use the water for a while the water near the heat source stays warm. When you turn on the water the water will seem warm at first and as the water further downstream (which has cooled off) comes up, the cooler section flows through until the hot water in the water heater gets to your fixture