Raster layers can be configured to display a gradient color-ramp legend. This functionality can be leveraged to create a faux legend to accompany a vector layer. This workaround is more convoluted than the other 'insert a rectangle' workaround, but it does result in a native legend item, which might be preferable in some situations.
For starters, here is my vector point layer styled using a color ramp. This screenshot shows a simple Print Layout consisting of a map and the default legend:
Now I add a random raster file to my project. I have added a small GeoTIFF of DEM data.
I then set its symbology to use the same color-ramp as the vector layer:
Next, in the Print Layout's legend's properties, I can configure the raster layer's legend item with values to make it appear to represent the vector layer:
Then I clean up the legend items, renaming the raster layer's entry in the legend, removing the Band 1 sub-title, and removing the My Vector Layer legend item.
This results in a print layout like the following. Note that I have hidden the bogus raster layer from the map:
I can also use the Orientation parameter to make it a horizontal legend patch: