I just started bike commuting, and the two times I've gotten flats were when I was biking on the sidewalk, and in both cases they seemed pretty random. I use a mountain bike. Is it just a coincidence or is there more to it?
There's almost certainly more debris on the sidewalk.
Sidewalks are swept less often, and vehicle movement pushes debris off the travelled areas. You can more easily see the latter on wet days - there will be wheeltracks from motor vehicles with much wetter areas between. The worst areas are the edges of major roads, where debris gets pushed into the bike lane by passing motor vehicles.
On my ride to work the most puncture-prone area is where the bike path crosses a major road - there's a shield wall between the road and nearby houses and at the break in that wall is a small space for people to wait before crossing. That acts as a dust trap for all the stuff thrown up from the road and is rarely or never swept. It's common to see broken glass, sharp metal fragments and even nails in this spot.
I often carry a pair of secateurs and a small hand broom in my pannier so I can clear plants and debris from the bike path. It's a small amount of extra work but it helps a lot, especially on Monday mornings when the bike path often has broken alcohol bottles on it from the weekend.
Sidewalk cycling is also much more dangerous so should be minimised.
I guess (I never ride on the sidewalk) that, if your tires aren't properly inflated then you may be more likely to get a "pinch flat": because you'll be hitting and climbing kerbs more often.
Also, when I got bored of getting flats during commuting, I changed my tires to (puncture resistant) 'Marathon Plus' touring tires.