One of the few absolute truths about education in the United States is that it is very hard to speak to national patterns (with a few exceptions.) Due to courts' and lawmakers' interpretation of the Constitution, education is a matter mostly left up to the states and as such, there's technically no such thing as "American education." At the same time, children do not have the right to a particular style or quality of education (though this may change as there are a number of court cases winding their way towards the Supreme Court.) Finally, it's worth stating explicitly that public education isn't compulsory in the strictest sense of the word. Homeschooling is legal in all 50 states (more on that history here if you're interested) and parents are not required to send their children to a public school.
What all this means with regards to your question is that each state has its own history of compulsory education as do different groups of children; the nature of "compulsory" for Indigenous children is different than for white children from families with means and access to power. Meanwhile, while there were states that had compulsory education laws on the books in the mid-1800s, they were functionally meaningless in many states as operational systems for documenting the count of children in a community and ensuring they were in school didn't fully take shape until well into the 1900s. Which is to say: it's difficult to boil it down to a single narrative.
That said, it's safe to safe that those making decisions about who got to go to school (mostly men, mostly white, mostly non-disabled) were not overly concerned with the concept of equality as we think of it today. From an older answer of mine on the discussions around public education:
The first law related to public education in the American colonies is generally recognized as Massachusetts' "Old Deluder Satan Act", passed in 1647. The law required every town with more than 50 residents to build a school and provide a tutor to the community's children. The law stemmed from religious leaders' fear children weren't sufficiently literate and may fall victim to Satan as a result of their illiteracy. Just a few years later, Boston Latin School was founded, making it the oldest public high school in America. The only children, though, who attended BLS were the sons of White men with access to power or discretionary income...
The public discourse around public education is deeply linked to the notion of which children count as members of the public. It's fair to say that American states didn't truly offer public education until 1975 and the passage of the Congressional Education of Handicapped Children Act, later re-authorized as the Individuals with Disabilities Education Act. The law requires all public schools to accept children with disabilities, meaning a school could not turn a child away for having, or thinking they had, a disability.
The reason this is significant is it's common for authors or websites to assert all states had compulsory education laws by the 1920s but the fact public schools could legally refuse to admit a child with a disability reminds us that "compulsory" didn't apply to all. And even if someone from a particular state asserts they had compulsory education laws for all children prior to IDEA, the disparity in resources was significant. The history of Rosenwald schools in Texas provides some additional context on that particular point.
Your second theory was about immigrants and it's safe to say that yes, in many cities, compulsory education laws were related to an influx of immigrant children. It wasn't, though, a straight line. Uninforced compulsory education laws were no match for child labor if a family needed the income a child could generate. Likewise, the laws were meaningless if there was no place for children to go to school - be it a function of safety and overcrowding in cities, or inaccessibility and a lack of teachers in rural areas.
Rather than compulsory education laws, though, the best way to understand how the system responded to immigrant children likely lies in a different construct. Two historians, David Tyack and William Tobin coined the phrase, "grammar of schooling" to describe a loose collection of norms and routines that identify American schools as schools. These include norms such as calling teachers by their last name and a gender identifier, apple motifs, having the "front" of a classroom, etc.
In addition to these norms, there's a concept in the grammar of schooling that's described as Americana. From an older response on the history of the pledge in schools:
Americana can best be thought of as the packaging of American history and touchstones for the next generation. It's a framework that led to the "Washington and the cherry tree" genre of stories, generations of school children memorizing the preamble to the Constitution, learning Christopher Columbus "discovered" American and mass dislocation and genocide of Indigenous people was simply "manifest destiny", and other broad strokes about what happened on this soil. This simplistic approach to American history was embedded in the texts children read and the way teachers talked about history.
A great deal of the motivation behind this approach to teaching history was about adults' concerns regarding immigrant children what it means to be American. And it was a very particular history, organizing around a White Ango-Saxon Protestant History that lays ownership to the phrase, "we the people" but focuses more on the Great Men theory. So, yes, immigrants likely played a role in shaping some compulsory education laws but it was idiosyncratic and shaped by how those in power viewed those who came into their community from other places.
If you're so inclined, I've written about education from the other side. That is, the decisions made by immigrant parents about their children (and the presence of compulsory education laws rarely played a role in their decision-making process.)