Those courtyard-style apartments don't exist because of crime. They exist because it's nice to have a courtyard.
Most apartments in the Bay Area have no outdoor space other than a balcony or a small piece of land on the ground floor about the size of the balconies above. Many don't even have that.