You will first need to partition & format the entire physical drive since older versions of macOS don't recognize the newer drive layouts & file systems. Here is an article showing how to do this for macOS 10.6 to 10.10:
https://eshop.macsales.com/tech_center/formatting/Mac_Formatting_6-10_R3.pdf
You can try booting into Internet Recovery Mode using Command + Option + R to attempt to access the online macOS 10.15 Catalina installer (does not always work and may just give you the macOS 10.8 Mountain Lion installer instead). Even if it gives you macOS 10.8 again, this key combination should prevent the need to authenticate with your AppleID to access the installer which is best when giving the laptop away.
If you have access to another Qualifying Mac, then you create a bootable macOS USB installer using the instructions in this Apple article:
How to create a bootable installer for macOS - Apple Support
A Qualifying Mac is one which is compatible with the OS installer you are trying to create. You can use this article to see which versions of macOS are compatible with various Apple hardware:
https://eshop.macsales.com/guides/Mac_OS_X_Compatibility
Generally:
For a macOS 10.11 installer you need a Mac from 2008 to 2015
For a macOS 10.13 installer you need a Mac from Late-2009 to 2018
For a macOS 10.15 installer you need a Mac from 2012 to 2019