It doesn't strike me as practical. Yes, such a thing could be built, but the tradeoffs would not be attractive. The escape section would have to be self- contained pressure vessel. Adding one large enough to carry the entire crew, or two smaller ones that combined could accommodate the entire crew, would require a substantial amount of additional metal. Some additional systems would be needed as well... and for a space that normally wouldn't get utilized. Subs are very much about packing maximum combat capability into the available space. The crew amenities that are included are there to enable extended operation.
Submarines, as with space craft, have space at such a premium, you may as well build a second submarine/hull.
"The Space Shuttle was fitted with ejection seats for the two pilots in the initial "shakedown" flights, but these were removed once the vehicle was deemed operational and carried additional crew members, which could not be provided with escape hatches. Following the 1986 Challenger disaster, all surviving orbiters were fitted to allow for crew evacuation through the main ingress/egress hatch, although only when the Shuttle was in a controlled glide, as the crew would have had to reach the exit from their seats and jump out."https://en.wikipedia.org/wiki/Launch_escape_system
A total waste of money to appease the public conscience by giving the appearance of a chance for survival in the event of an emergency.
Spacecraft and submarines are inherently dangerous. God bless all those brave enough to venture forth in them.