I haven’t been able to track down exactly when the expression was coined, but, in the Google Books corpus, anyway, balls deep first rears its head in 1988, from FirstHand magazine: “Within seconds I was stuffed balls-deep into his tight hole.”
No ambiguity there. This sexual sense of balls deep—where your penis is so far in someone (or something) that it can’t possibly go any further—was common in gay erotica and later spread to mainstream usage.
Yet, also in 1988, in the Canadian Alpine Journal, we see the other sense of balls deep: “At 3 am we tromp across the snow covered moraine only to plunge balls-deep in the unfrozen soup. A chorus of bitching rises into the dark…”
Of these two literal senses, the first dominates, although you see the second enough—as in this Reddit thread about standing balls deep in water and the lyrics “You’re balls deep in muddy waters” from Tool’s “The Pot”—that it still seems intuitive.
Figuratively, judging by the Corpus of Web-based Global English (GloWbE), balls deep is more evenly split between “all in” or “fully committed” (e.g., “I am going for it, balls deep… and if I get heart-broken you will read about it…”), derived from the sexual sense, and “inescapably mired” or “overwhelmed” (e.g., “The whole peninsula is balls deep in cops now”), which is semantically closer to the other sense. Sometimes the distinction isn’t so clear: Does “He was balls deep in his project” convey commitment? Stress? Both?
This bit of ambiguity may be why the term has proliferated—as movie and album titles and band names—largely unchecked by censors. Why not give your endeavour a risqué name, when you can, with both a straight face and tongue firmly in cheek, claim you meant nothing sexual?