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.
Some hitchhikers complain that their identifications are asked by the police while hitchhiking. Fabzgy blogged about his experiences here and some others added their experiences in the comments. (feel free to submit your experiences)