It depends on which "context" (or "mode") you are in.
If you are writing a news article and trying to explain what primes numbers are within an ordinary Japanese sentence, you should be using Japanese style punctuation.
On the other hand, when you are writing an academic article or a math textbook, it's common to temporarily shift to "math mode", where Western style commas must be used. The Wikipedia article you saw has many examples of this.
The yellow parts are in the "(inline) math mode" (i.e.,
$n-1$ if you know TeX), so Western commas are used. Outside these contexts, Japanese commas are used.
The same can be said with regards to English words. If you are introducing one or two English nouns in an ordinary long Japanese text, the base text is still in Japanese, so you should follow the Japanese orthography and keep using Japanese commas. If you are citing a long English sentences, you should switch to English mode and use the English punctuation.