Ice works by narrowing the space inside the blood vessels, which limits blood flow and decreases the metabolic requirements of your soft tissues. The limited blood flow also reduces the amount of irritating chemicals that are delivered to the injury site. While these chemicals are a natural and useful response to inflamation, they must be kept in check to avoid swelling, and excessive formation of scar tissue at the site of your back or neck injury. Ice also acts as an anesthetic to reduce the pain of injury.
For back strain, the rule of thumb is ice (and aspirin) for the first 48 to 72 hours. Heat increases the inflammation, and it is not a good idea to use it during the inflammatory phase. After those first few days you can use ice or heat, based on your preference. While researchers continue to look into the best ways to treat an acute injury, most doctors still recommend ice as a first line of defense to their back injured patients.