For pronunciation of a foreign language, do foreign speakers from a certain country speak with the same accent because they learn in their country from someone with that accent, or their native language phonology make it so that they feel comfortable speaking like that? If both are at play, most likely, what's the dominant cause?
In some cases this would likely be due to L1 transfer and differences in the markedness of features between the L1 and target language. Markedness in second language acquisition refers to a closed set of linguistics possibilities, ranked from most 'simple' and frequent in languages (unmarked) to most 'complex' and rare (marked). In most cases, a more marked form will not exist in a language without the less marked form also existing in that language. An example is voiceless and voiced stops. Voiceless stops are present in all languages to a degree, whereas only some languages have voiceless and voiced stops, and there is no language that has voiced stops only. Therefore voiced stops are consided the more marked member of the pair.
The way that this is linked to speakers of a certain L1 making similar 'mispronunciations' when learning and using an L2 is that, in general, when learning forms that are more marked in the L2 than the L1, this can cause difficulty. An example is that German learners of English have difficulty pronouncing voiced stops at the end of English words (e.g. they will pronounce 'tab' with a /p/), because in German, there are no word final voiced stops -- all word final stops are made voiceless, or devoiced. On the other hand, English learners of German usually have no trouble with the word-final stop devoicing rule of German, as they are already familiar with the more marked form via their L1. This should also apply to similar L1/L2 pairs where the L1 has the less marked phonological feature than the L2.
Of course, there are many other factors that would contribute to someone's accent, but this would account for some of the common 'mispronunciations' at least. But yes, in most cases the native language phonology would account for the L2 accent more than the accent of those who the L2 is learnt from.
Source: Ortega, L. 2009. Understanding second language acquisition. Routledge. pp. 37-38.
In part, it is due to a third factor, the local dialect of L2. In the case of French as taught in the US, to the extent that there is a characteristic American-accented version of French, it is primarily because of properties of L1 (American English). In some countries and for some languages, it is because of the properties of local L2. English is a prominent example in countries like Kenya, India and Nigeria, because there are local versions of English. English teachers in Kenya generally speak a version of Kenyan English, not British or American English. Because English is a national or official language and is widely spoken in these countries, there are ample local exemplars that learners are exposed to.
It is true that a number of L2 English speakers have phonetic traces of their first language allowing one to tell that so-and-so is Kalenjin or Kikuyu, so not all speakers have the exact same accent, but if you focus on those that do have generic Kenyan English pronunciation, that accent is not a function of their L1. Instead, it is the function of the L1s of their ancestors, and the ancestors of their neighbors, who contributed to the averaging-out that constitutes "Kenyan English".
There is also a universal Kenyan English substrate, where there is something that ties together all Kenyan English speakers (likewise Indian English and Nigerian English), even when you can say that the person has a clear Kikuyu accent to their English. This is not surprising, since the phonetic models are Kenyan English, and we can't explain the nature of that universal substrate by appeal to just British English plus the L1 of an individual.
The question has a presupposition that there is some place where speakers from that country all speak the/some L2 with the same accent, which I think is wrong if you mean "exactly the same", but is right-ish if you mean "approximately the same". Even L1 French speakers in France don't all talk the same.
By far the biggest cause is differences in the phonology of the first language and the target language.
Whatever sounds are in your first language (your phonological inventory) basically is your base when you start speaking a new language. If you do not expand your phonological inventory so it includes all the sounds of the new language, you just make do with whatever you have at your disposal.
If you want an example of this, compare the vowel sounds in English and the vowel sounds in Spanish. Until they have mastered English, Spanish speakers use a very limited range of vowel sounds (the ones that exist in the first language or are close to those that do).
Another non-trivial reason for mispronunciation is poor awareness of the inconsistent relationship between written English and spoken English. Many non-native speakers of English will 'overpronounce' words by pronouncing the silent letters (eg. producing the silent 'S' in the word 'island) or ignoring the omission or blending of syllables (in words like 'comfortable' or 'restaurant').