Where do PhD scholars get data to test their thesis on? For example PhD scholars working on ML/AI algorithms need a lot of data to train and test their research. Research on distributed systems might require terabytes of data to test.

Where do these scholars get so much data i.e. the scale which is only produced in big companies?
The question is very vague. For some fields such as linguistics/language there are huge open-access research corpuses available such as the British National Corpus, maintained by academic or charitable organisations. For some things, e.g. images, you can also use open, permissively-licenced sources like Wikimedia Commons, which offers a lot of APIs for searching and processing; the Internet Archive has a huge collection of video, texts, audio, etc. For some subjects it is possible to use internet searches or other archives. Many commercial entities will have large databases and research project are often done in conjunction with a commercial partner, as mentioned in a comment. You can also purchase data, but that will probably require a commercial partner to pay for it.