It means that in a dark, terrible, and troubling situation, one is forced into strange circumstances. Today, we use the phrase metaphorically. But, when it was first used in Shakespeare's play, the character used it quite literally as he was settling down to shelter alongside a strange inhabitant (Caliban) of the island he’s shipwrecked on.