The Database and client configurations for query layers say:
Query layer names are limited to 158 characters. When adding a feature class or table from a database connection in the Catalog pane or Catalog view to the map, the default name used for the query layer is the fully qualified name of the table. If the fully qualified name of the source table in the database or cloud data warehouse contains more than 158 characters, adding it to the map from the Catalog pane or Catalog view will fail. In these cases, use the New Query Layer dialog box to create a query layer, and define a query layer name that contains fewer than 158 characters.
Why 158 characters? That number seems arbitrary.
Enterprise geodatabase size and name limits—ArcGIS Pro | Documentation
might be tied into the 159 character limit imposed on feature datasets 😉