Usually you don't have anything to fear from the police when hitchhiking.
Though there are some areas in the world where it's forbidden to hitchhike, such as a couple of states in the USA and according to some cops in Australia it's forbidden in that country as well (but possibly only in their jurisdiction, and only because they say so).
In China the police generally acts really confused but extremely friendly. Sometimes they even offer free bus rides (which are usually shittier than hitchhiking cars though).
In countries with an elaborated system of motorways you should avoid walking on the motorway. If you do, be prepared with some kind of excuse. On the other hand, you can use the police as a means of getting out of shitty spots - if you're stuck on a bad on-ramp, just walk onto the highway and keep walking until the cops show up. In countries like France, this isn't going to take very long while in Sweden you might wait (and try to hitchhike?) several hours. The cops will usually tell you off and take you to the next on-ramp. It's not recommended using this kind of strategy more than once per day/area.
In France it's mostly a bad idea to be on the motorway, but standing close to the Peages is mostly tolerated - unlike in many other countries such as Italy and Spain. However, at times, one can be completely barred from hitching at a péage. When in France, if the Gendarmie are at a péage doing random identification checks, do not get out, continue to the next possible stop and hitch back if necessary. You will not be ticketed but often you will be limited to hitching out of the péage parking lot where not too many cars stop.
Some hitchhikers complain that their identifications are asked by the police while hitchhiking. It can be useful to keep a form of identification in your pocket for the police so as not to aggravate them. Fabzgy blogged about his experiences here and some others added their experiences in the comments. (feel free to submit your experiences)