Jane at Dear Author looked up the metadata for a number of books, both ranked and de-ranked, and it seems the stripping of sales ranks might've been done in accordance with the metadata, looking for "Gay & Lesbian" or "Erotica" in the metadata to choose what to strip. Books like A Parent's Guide to Preventing Homosexuality weren't stripped of their ranking because, despite being clearly about homosexuality, they don't have "Gay & Lesbian" in any of their metadata.
That explains how this could have been done automatically. There apparently is a consistent keyword-type search which could've been used to strip rankings on books which all had metadata features in common by someone typing in a command. I still don't buy the "glitch" story, though, because that doesn't explain why writers like Mark Probst were told straight out that the de-ranking was done by Amazon, per their policy of removing "Adult" material from searches and listings. Why would anyone have said, "Yes, we do this, it's policy" if it was actually a glitch? Sorry, Amazon -- I'm still not buying it.
Note also that someone came up with the tag Amazonfail and people have been applying it on Amazon to books which had their ranking stripped. This isn't something that's going to force Amazon to do the right thing; they can and likely will delete the tag as soon as they notice it. I'm willing to spend some time tagging and confirming tags just to be annoying, though; have fun if you have some free time.
I did notice that some of the books which have been used as counter-examples ("Why were those books de-ranked and not these?!") have been included in the Amazonfail tagging. I didn't confirm those; I still think that all the books should have their rankings and be included in searches and listings. No matter what I personally think of some other books (the historical manual on dogfighting, for example) I oppose all censorship and suppression of books and won't even suggest suppressing books I disapprove of, any more than I approve of anyone else censoring books I like. That's just me, though.