You would expect a title to be capitalised when it is unique and you are naming that unique role.
In your example, you used 'district attorney' with the definite article, 'the', making it unique. There may be many district attorneys, but in any specific area there will perhaps be just one, making it unique in that context.
For example:
- He works as a district attorney.
- He is the District Attorney
Also consider whether you are using it as a title or not. For example, lets say your job title was "Senior Writer", and that was a unique role at your workplace. Nobody else held that title; however, there are many other writers. You might say "I am the Senior Writer", using your full title, but you might also say "I am the senior writer", using 'senior' as an adjective and 'writer' as a non-unique name for your role. You are, in fact, saying that you are senior among all the writers. It is possible that "district attorney" could be used the same way, with 'district' acting as an adjective to set the position apart from other attorneys.