Yes, stop-words can be detected automatically.
Word frequencies as a whole
One way is to look at word frequencies as a whole.
Calculate the frequency of all words in the combined texts. Sort them in falling order and remove the top 20% or so.
You may also wish to remove the bottom 5%. These are not stop-words, but for a lot of machine learning, they are inconsequential. Maybe even misspellings.
Words per "document"
Another way is to analyze words per "document."
In a set of documents, stop-words can be detected by finding words that exist in a large number of documents. They would be useless for categorizing or clustering documents in this particular set.
E.g. a machine learning system categorizing scientific papers might, after analysis mark the word "abstract" as a stop-word, even though it may only exist once per document. But in all likelihood in almost all of them.
The same would be true for words that are only found in a very limited number of documents. They are likely misspelled or so unique they might never be seen again.
However, in this case, it's important that the distribution between document groups in the learning set is even or a set divided into one large and one small group might lose all its significant words (since they may exist in too many documents or too few).
Another way to avoid problems with unevenly distributed groups in the training set is to only remove words that exist in all or almost all documents. (I.e. our favorite stop-words like "a", "it", "the", "an", etc will exist in all English texts).
Zipf's Law
When I studied Machine Learning and the discussion of stop-words came up, Zipf's Law was mentioned. However, today I couldn't tell you how or why, but maybe it's a general principle or mathematical foundation you'd want to look into...
I googled "Zipf's Law automatic stop word detection" and a quick pick found me two PDFs that may be of interest...