From my personal experiences I have only been flagged once by customs and this was at LAX which is similar to the OP. First, i made it through immigration with no problems except the agent saying my passport was in poor shape and should be replaced, after grabbing my 2 bags i was going through the nothing to declare line and was directed over to the special screening line. When I got there I received the thorough bag search and a lot of questions about my work, where I visited, and what I went traveling for. The agent then asked me what was on my laptop and numerous memory cards and asked permission to search my laptop for pictures. Since I always make sure to take a clean laptop out of the country I said go ahead and the agent did a search for jpg files and found nothing of interest. Over the whole course of this the agent and I talked a bit and he explained how most likely I was simply flagged because I was a solo traveler coming back from Asia with no business reasons to be there. In addition, I should add in that the agent that did the search was professional and kept everything as neat as possible.
Since this experience I have passed through customs at ORD and SFO a few times and previously I had gone through customs before without any problems. IMO, I would say this is simply either the OP just looking like an interesting person for a thorough customs search for the customs agents or simply the agents are just more thorough when you have been passing through LAX.
In the future, try entering through another international gateway and see if you have the same results. Also, where were you flying in from on these 2 incidents and were you traveling solo?