if humans are naturally good, why do we need to prevent them from being bad (via the power of the state)?
The premise is inaccurate insofar as it obviates Rousseau's distinction between savage man and civilized man. Rousseau certainly attributes to the savage man the attribute of natural compassion, and altogether characterizes him as "rather wild than wicked" (all quotes here are from his work "On the Origin of the Inequality of Mankind").
In addition to that state of wildness, Rousseau identifies in the savage man related attributes such as the rule of instincts, a lack of foreseeability, of dependence on other men, a lack of passions, and inextricably a lack of understanding. By contrast, Rousseau's term civilized man refers to man with passions, understanding, planning, a sense and sake of private property, ideals of self-preservation, and entangled with relations of dependence on other individuals.
Rousseau's premise is that civilized man's attributes "made man wicked while making him sociable". These also made him paranoid from realizing that other individuals are like him. This paranoia or fear leads civilized man "to pursue the rules of conduct [...] for his own security and advantage".
why, for instance, doesn't he advocate to return back to a pre-civilized state
Because Rousseau acknowledges that civilization is essential to progress. For instance, without society, "[e]very art would necessarily perish with its inventor, where there was no kind of education among men, and generations succeeded generations without the least advance". Rousseau asks "What progress could be made by mankind, while dispersed in the woods among other animals?", an obvious allusion to living in a state of nature.
From this standpoint, civilization is a necessary evil. But enacted laws supposedly are for curbing the "enormous injustices" that inevitably ensue from society.