In computer science the first author does the work and is usually a PhD student. The last author is usually the professor that pushed and helped develop the idea, provided funding, and probably wrote or was heavily involved in writing the paper’s abstract, intro and conclusion sections — the bulk of “framing” the work.
But there are exceptions. Some profs are less student-oriented or don’t like delegating so much, and remain “individual contributors” deep in their careers. Those tend to publish nonzero number of first- and single-author papers.
Edit: I’ve noticed that in Theory and Algorithms, profs tend to take first author even though the student slaved out the proofs. That field is kind of an outlier in that it’s close pure math, and I think borrows cultural artifacts from math research.
In a lot of math disciplines, the papers follow the Hardy-Littlewood rule, so the author names are ordered alphabetically [1]. Maybe, that's what you've been noticing. In my area (programming languages, which may be sometimes theoretical but it's mostly a mixed bag), I noticed only one group follow that convention. Others follow the "first author is the main contributor, last author is the advisor" convention you described.
But there are exceptions. Some profs are less student-oriented or don’t like delegating so much, and remain “individual contributors” deep in their careers. Those tend to publish nonzero number of first- and single-author papers.
Edit: I’ve noticed that in Theory and Algorithms, profs tend to take first author even though the student slaved out the proofs. That field is kind of an outlier in that it’s close pure math, and I think borrows cultural artifacts from math research.