How do I preserve the underline when converting a text object into a path?
Preserving the underline is not possible in the current release version of Inkscape (1.2). You may only (manually) create and add an appropriate underlining path.
Inkscape is still in progress to reach a full compliance with the SVG standard, so there are still SVG elements / attributes which are not supported, or are supported only partially.
The text-decoration
is an example of such a partially supported attribute – Inkscape don't ignore it and displays it, but it presently not considers it as a part of a text object.
It follows besides other things from the impossibility to apply underline style directly from the Tool Control Bar of the Text tool. You may only manually (although comfortable from the Inkscape XML Editor or Selectors and CSS dialogs) add this attribute into the resulting SVG (XML) file.