Recently, I came across a person who keeps doing something I don't like them doing, for various reasons (though those actions are otherwise fine, just something I don't personally like). However, after repeatedly explaining to them why they shouldn't do that in my opinion, and good reasons for not doing that, they keep doing it.
Now, it could be that they have legitimate reasons for doing that thing. If so, I want to know those reasons, so that I can then stop telling them not to do it. Now, I could simply pull them aside, and ask:
Why did you keep doing [x] even after I told you not to do that?
This asks them "why" they did it, but often comes across as my being mad at them, and asking them for an apology rather than an explanation. (In fact, when the reverse situation applies to me, I usually respond with an explanation, but that comes across negatively as "justifying" my actions - in this case, I want the other person to respond in the manner generally considered "justifying".)
One option is to say:
Why do you keep doing [x]? Can you tell me the reason?
But in most cases when I used that, it didn't help, and in a few, it just added flame to the fire. There isn't even supposed to be a fire, I just want to ask for an explanation in a nice way. What's a good way to do that?
Update: I'd like to explain the specific situation that prompted me to ask this. I kept this hidden before because I thought people would be quick to reach for the "close" button without bothering to see that the question is on-topic and applicable to real-life situations as well. In fact, I want an answer that does explain in real life, because this has happened with me in real life too in the past quite a few times:
On a certain Stack Exchange site (my most active one), there is a user who goes around editing recent posts mostly for spelling and grammar, i.e. minor edits. On most posts, including all answers, open questions, and closed questions that were closed more than five days ago, this isn't a problem, and I appreciate what they do. However, on posts closed within the last five days, this presents a problem, and these constitute a significant proportion of their editing. If a question closed within the last five days gets edited, it goes into a review queue for possible reopening in case it was edited to fix the original problem with the post; as their minor edits do not fix the post so that the original close reason no longer applies, we have to vote against reopening the post (this creates extra work for three users, the required amount to dequeue the post). Additionally, posts are only added to that review queue once per closure by editing, so by making their minor edit, this user is depriving the post author of their chance to have their own question reopened.
Thus far, I've left comments pinging them on the posts they've edited, requesting that they refrain from editing posts closed within the last five days. Despite that, they have neither ceased editing such posts nor responded to a single one of my comments. I'd like to know why they still edit those posts. As I'm a reason-oriented person, giving me a good reason as to why they're doing it is enough for me to understand and stop questioning them.
In the spirit of one of the answers, I've attempted pinging them in a chat room on the site where this is happening, but they haven't responded to that at all.