Use Supadata which is a free API offering access to YouTube transcripts.
Specifically, the /v1/youtube/transcript will do what you ask for - return a transcript by video ID.
/v1/youtube/transcript