I'm installing a water heater when I opened the junction from the the house there was a black wire, a white wire and a black and a white wire nutted together. What is the purpose of this and what should I do?
It's fairly likely that the power comes first to the heater, and then has a "spur line" going to the switch or thermostat. That "spur line" is wired as a switch loop, which by the way means you will not be using 240V smart switches.
Leave the black-white nutted wires together. This is less important here, but vitally important on 120V switch loops. Generally when doing swaps like this, take careful note (mark) which wires the old device was connected to, and don't disturb any wires except those.
The two capped-off wires are surely the ones that went to the old heater, and should go to the new heater.