According to W3 schools
All HTML documents must start with a <!DOCTYPE> declaration. The declaration is not an HTML tag. It is an "information" to the browser about what document type to expect.
Let's talk about the DOCTYPE history a bit
The early era of HTML was started from XML and all browsers were crazily developing it on their own and had individual HTML standards that made different rendering behaviors on browsers. It was really a hard time for most web developers.
And then W3C was established to standardize HTML for all websites, but the problem was how we can develop a new standard HTML but still keep the original HTML's behaviors on current web pages? They thought a new term for this backward compatibility which is Quirks mode, and DOCTYPE was born for new web standards, so most modern websites need DOCTYPE as the entry for understanding which HTML version developers writing to give consistent rendering across browsers.
Well, I think we have enough theory and history background, but with the human curiosity trait, I think it's not enough for us.
I can share a very good example of what will happen if you have and don't have DOCTYPE
in your HTML.
Here is the code snippet
<html lang="en">
<head>
<meta charset="utf-8" />
<title>The Transitional</title>
</head>
<body>
<h1>Header</h1>
</body>
</html>
BUT you need to save that code snippet as a static HTML locally to see differences on browsers because nowadays, the latest browsers always populate DOCTYPE for you if you don't put it even though that automatic population also happens to most front-end development tools/frameworks. On top of that, all browsers have adapted to HTML5 for a long time, that's why now you're seeing very less people have mentioned problems around DOCTYPE.
Without DOCTYPE <!DOCTYPE html>

Once you inspect, you see H1's margin is 21.44px 0px
which means we're expecting to see the top and bottom margins are 21.44px
but that top margin is not applied correctly without DOCTYPE!
With DOCTYPE <!DOCTYPE html>

Yeah! Now we can see H1's margin is correct for top and bottom as expected.
I think it's good enough for the explanation. Feel free to reach out to me if you are still concerned about it.