There's not an "ideal" video length, but there are guidelines. TechSmith (creators of Camtasia) found the preference by viewers falls into two primary buckets: 3-6 minutes and 10-19 minutes.
When planning videos, I usually have "explainers" (informational) be less than 6 minutes long. "Get to the point, quickly."
For how-to's (instructional), I aim for less than 15 minutes. "Tell me what to do exactly but keep it succinct."
Courses are usually a mix of informational and instructional clips. The same length guidelines apply there too. Overall, courses are usually around 90-120 minutes unless it's a Fundamentals-style course, where each module might be 90 minutes.
In the wild, you'll see YouTube courses that can be hours in length with 500K+ views, but the key here is that they have chapters defined, making it easy for people to stop and resume. Each chapter follows the same length guidelines. In that case, it's more convenient to have it all in one long video vs. separated (easier to update, too).
Have a lovely day,
Kamran