I think all the things you suggest are potential factors in cases like you describe where someone speaks a foreign language with the accent of their native language. They may not have any interest in working on pronunciation or achieving the accent of the target language, and this may be related to issues of identity, for example if they see themselves as English rather than Spanish. Besides that there are probably, as you suggest, individual differences in how much people can “hear” accents and take them on. And learning a language by reading rather than listening can definitely lead to speaking with the sounds of one’s native language, since one will generally only have those sounds available to them to use in reading the words.
The last one points to what I think is the overarching factor in how well one speaks with the accent of their target language: the extent to which one has gotten listening input in the language before speaking (and reading).
From my experience I find with listening to enough comprehensible input in the target language BEFORE speaking it much it actually can become hard to NOT speak with the native sounds.
To give two contrasting examples: When I studied French one of my goals was to speak with a good accent, so I put effort into practicing the French accent and pronunciation (It likely helped that I had heard how French should sound over the years incidentally from things like French TV and radio and some French classes at school that I didn’t actually learn much of the language from because they didn’t provide much comprehensible input).
In my French self-study, I first used textbooks and focused on practicing reading, writing, listening, and speaking all at once. I have gotten compliments on my ability to pronounce French, but I’ve found this breaks down when I can’t focus on correct pronunciation because I have to focus on other things like conjugation or how to say what I’m trying to say. Things improved somewhat when I learned about comprehensible input and started focusing on listening, but this was late in the game, and I soon moved on to other languages.
Later, I began learning Thai in a unique program that’s based on just picking up the language without study by listening to teachers who speak it while using things like drawings and gestures to make it comprehensible. In this program students are not supposed to try to speak the language or even think about it (e.g. by comparing its sounds with those of their native language), but instead, just let it become clear and speak only what “pops up”, that is, what comes to mind without effort.
I followed the approach and found that gradually I could say more and more without effort, starting with some words and phrases and eventually sentences. I’m not fluent yet, but I frequently get comments from native Thai speakers that I speak very clearly, and I find that I almost never have problems being understood that are because of my pronunciation.
Much more than French, Thai is reputed to be a difficult language for English speakers because of its tones and other features. While one of my goals, as with French, has been to speak it with a good or even native-like accent, I’ve found that I’ve never really had to put any conscious effort into speaking with the correct tones or pronunciation. It’s just come on its own more and more after listening and understanding a lot first before speaking much, and I find it takes more effort to say things wrong than right.