This seems to be the subject of some debate, in-universe and out-of-universe.
From Ex Astris Scientia's article on warp propulsion:
Although it is definitely possible, there seem to be very different opinions whether it is advised to go to warp inside a solar system. In Star Trek: The Motion Picture, Kirk speaks of the risk of engaging the warp drive while still in the Sol system. Dax advises against going to warp inside the Bajoran system in DS9: "By Inferno's Light". In ENT: "Demons" T'Pol is worried ("Inside the system?") when Paxton orders the mining facility to go to warp. In TNG: "The Best of Both Worlds" we even see the Borg ship as well as the Enterprise-D slow down to impulse, although several seconds longer at warp speed may have saved precious time.
It has happened, however, on some notable occasions, without resistance to the idea and also without consequence:
- Zefram Cochrane's first warp flight in Star Trek: First Contact takes place in the Sol system
- Later warp tests in ENT: "First Flight" all occur very close to Earth too
- The Enterprise NX-01 goes to warp within seconds after leaving the drydock in ENT: "Borderland"
One might counter that they probably didn't know any better, considering the technology was new. However:
- Kirk's Enterprise goes to high warp in the Sol system in TOS: "Tomorrow is Yesterday"
- In TOS: "Operation — Annihilate!", the Enterprise jumps to warp 8 within a solar system to pursue a Denevan ship
- In TNG: "11001001", Picard's Enterprise goes to warp just after departing a starbase, which itself was orbiting a planet
- In TNG: "Symbiosis", the Enterprise goes to warp within a solar system in order to rescue an Ornaran freighter
- In TNG: "Descent II", Beverly Crusher orders the Enterprise to drop out of warp directly beside a planet
- In DS9: "Past Prologue", two runabouts criss-cross the Bajoran system at warp speed
So what's the risk then?
Given that it is okay sometimes and ill-advised at other times, there must be specific reasons for why it is dangerous in some situations. The same Ex Astris Scientia article posits:
Gravity may obstruct warp propulsion in the vicinity of a planet, but most likely the much higher concentration of particles inside a solar system poses a problem. Modern starships have a deflector for that purpose. Cochrane may not yet have been aware of the danger, and he may have just been lucky that nothing collided with his ship. Still, it is possible that the Phoenix already had a navigational deflector. Even with a deflector, warp flight may be still a risk at high particle densities. In addition, it is possible that warp ships may endanger intra-system sublight traffic, so regulations may have been set up that generally disallow warp flight inside a (Federation) solar system.