John Mueller from Google shared some important pieces of information regarding how URLs that are invalid are treated by Google. According to Mueller, every webmaster must make sure that their invalid URLs always return 404 errors and not 5XX errors.
404 errors help Google understand the fact that these URLs are independent of any site. On the contrary, 5XX errors are quite different from those and are essential indicators of server errors. Here is what he exactly tweeted in the recent past:
"Got an alert from Google Search Console today that one of our pages is 5XX - after investigation, it's a mention of our link in the footnotes of a scientific pdf article: as there is a semicolon right after the url, the url is not valid. Had no idea @googlewmc was this thorough!"
Also, Mueller suggested that owners of websites should avoid such URLs that can lead to 5XX errors. According to him, Google keeps on crawling the 404 pages as long as there is any signal on the internet.