You should include enough detail to convince the grader that you understand what you’re doing. The actual amount will depend on the grader and on the level of the course. In your example the first answer might be appropriate in a first introduction to algebra in secondary school or in a low-level remedial course in college and the second in a brush-up pre-calculus algebra course, while at any higher level you could probably go directly from $5x+7=17$ to $x=2$.
Once the term is well under way, it may also depend on the impression that you’ve already made: I’ve generally wanted to see a bit more detail from weaker students than I need to see from the stronger students.
If you find the material fairly easy, you may also find that more detail is wanted than you think is necessary. You may well be right as far as explaining the calculation to yourself is concerned, but that’s not what you’re doing (except as a secondary goal): as I said, you’re really trying to convince the grader that you understand what you’re doing, and that may require more detail than you need to convince yourself.
The most direct way to find out what’s expected is to follow Todd Wilcox’s suggestion in the comments: prepare some sample answers, and ask the instructor. Failing that, a good rule of thumb is:
When in doubt, give a little more detail rather than a little less.
It’s certainly possible to overdo the detail $-$ in almost all college-level settings your first example would be overdoing it $-$ but in my experience it’s much safer to err on the side of too much until you discover the instructor’s sweet spot.