Time Machine only backs up what is on your Mac. Apple provides a support page on how to Archive or make copies of the information you store in iCloud, but the ultimate answer isn’t very satisfying. You simply have to make sure to archive things first. iCloud is very reliable, but it is not 100% guaranteed.
Perhaps a better answer is to turn off “optimize storage”, wait for downloads to complete, and then archive your local files. You don’t even want to use Time Machine for this. Time Machine is a backup. Like iCloud, although Time Machine is very reliable, it is not 100% guaranteed. If you later delete files, or replace them with optimized versions, the originals will eventually be deleted from Time Machine. If you have old files you want to save for posterity, you need to actually archive them to an external hard drive.