TLDR: A scrum master can either work himself out of the job, or be the change agent the team needs to successfully deliver.
It really depends on the scenario and situation. I've been part of teams that had a full time SM, and i've seen teams that functioned well enough without the "dedicated" role as well.
The way I approach this is by I ask the team if they are getting the value and benefit that the scrum master role is supposed to provide during retrospectives. Every role should be providing value towards the team delivering in some fashion anyhow right? Some scrum masters have tons of skills and traits that enable them to stay with teams longer (or even be a semi-team member) like assisting with XP logistics, team gamification, or product owner soft skills. A scrum master is only as valuable as the team's improvement and progress indicates. Improvements and progress can be "measured" in a plethera of ways whether it's team synergy, collaboration, quality, delivery, morale, trust, innovation, etc. Some scrum masters have enough knowledge and experience to drive those things, others don't. Since the norm for most scrum masters is the basics of scrum/agile processes, people tend to think that they can be weeded out fairly quickly (and most of the time, they wouldn't be wrong...thanks CSM). There is the concept of diminishing returns when team members start to "assume" the role of a scrum master. Teams naturally tend to start gravitating towards normal processes or ways of delivering after a while, which is why I would advocate to have a scrum master pushing outside the box thinking or approaches (if he/she has the mindset and those skills to begin with).
I could also argue that any position is really supposed to "work themselves out of the job". A developer that routinely codes business rules and logic services could simply build a system interface CMS that removes the need for that backend functional coding. A quality assurance person who routinely tests code or writes automation could implement/utilize a framework that auto detects functions/logic within the code and wraps test automation functions with variable property outputs (property based testing). IMO, it's not about working themselves "out of the job" but "out of the current problem". If a developer realized he/she wasn't providing value with his old frameworks and coding style, would they technically be worked out fo the job too? I see the scrum master role to be no different.