Well, first, the detection aparatus wasn’t all that efficient. Better than nothing, but still pretty primitive. Further, they couldn’t look “back” behind the attacker, so the sub had a chance for a couple minutes to maneuver as the attacker went overhead. For this reason, ASW forces tried to set up sequential attacks by multiple tin cans whenever possible. Next, at slow speed, a sub is very quiet, and can sneak along with a good chance of going undetected unless directly targeted by chance or an unusually skillful attacker. Next, depth charges make a huge racket when they go off, and create a mass of violently disturbed water that’s as good as a brick wall, where acoutic devices are concernted - just the ticket for shielding an evasive maneuver. Next, there are thermoclines, layers of differing water density that play games with acoustic performance, and if you can get a boat on the opposite side of a thermocline from its attacker, it’s like drawing a curtain over the boat’s mauevers.
Lastly, the ocean is a BIG place, and even when creeping along, a couple minutes of undetected sneaking can create a HUGE volume of water to be searched - all the boat has to do is create an opening of a few minutes, and they can increase the size of the search area into a volume so large that only random chance or extreme perseverence and skill would lead to re-detection.
Multiple depth settings was common. Trying to “bracket” the boat above and below was a standard thing. Mind you, the chances of any one depth charge being directly responsible for a kill was very low, but if you could batter a boat hard and long enough with near misses, you could tear it apart slowly, or cripple it to the point where it was forced to surface. Some boats survived attack by depth charges counting in the many hundreds. Four hundred charges, or more, were not unknown, and those were the attacks from which boats returned!
Elite service. In the German (WWI, WWII) and American navies (early part of WWII), the submarines were the only part of the naval force actually putting any real hurt on the enemy. For the Germans, it would mostly remain so; The American surface fleet finally got its act together. But in the those days, boats were where it was at, if you wanted to take the fight to the foe. Sailors, like any fighting man, want to think that they’re doing something, accomplishing a goal. The boats were getting it done, and so had their pick of the fleet personnnel. That allowed the sub force to be choosy, making the units ‘elite.’ Once a unit is established as ‘elite,’ the story builds upon itself, making the unit that much more desireable, leading to more and higher-quality applicants, further allowing choosiness by the fleet, and reenforcing the ‘elite’ image.