Get last segment of a line (connect 2nd last to last vertex)
To create the last segment of a line (connecting second last and last vertex), use this expression with Geometry Generator (for visualization) or Geometry by Expression (for actual geometries), see here for details:
make_line (
point_n ($geometry,-2),
end_point ($geometry)
)
Instead of end_point ($geometry), you could also use point_n ($geometry,-1).

Connect first and last vertex
This was the initial answer, before your clarification, when I supposed you want to just connect the start- with the end-point of a line. This can be done with this expression:
make_line(start_point($geometry), end_point($geometry))
Another option to create the last segment (by @Matt)
And here another version, proposed by @Matt (thanks for the initiative!):
with_variable('points',
nodes_to_points($geometry),
make_line(
geometry_n(@points, num_geometries(@points) - 1),
geometry_n(@points, num_geometries(@points))
)
)
