Stringer is a term probably as old as shipbuilding. In wooden ship and boat building, stringers have always been horizontal beams (or lathes in boats) on the inside of the ribs used to tie or "string together" the ribs so as to keep their spacing and thus strengthen the hull.
When you build a boat, it takes considerable time to attach all the planks along the ribs to close up the hull and if there was nothing to hold the top of the ribs in place during this process, the twisting forces of the bent planks would pull the ribs out of alignment. But if there's a stringer placed first every so often along the ribs, it keeps the spacing for the ribs.
After the outside of the hull is finished, the stringers are left in for added strength and can also be landing points for the edges of decks (or in small boats, thwarts or seats)
In U-boats of course, there are no longer any planks, but stringers are still useful to keep the ribs of the casing aligned and provide strongpoints for attachment to the pressure hull and for other pieces of equipment and bracing for the deck. Without the stringers, the casing might have a tendency to twist in the forward and aft parts that extend beyond the pressure hull. This could create a problem especially in the bow where the outer torpedo tube doors have to move.