A caveat to begin with: It's not definitive whether this particular use is or is not infringing, given that the circumstances haven't been tested in court.
The usual scope for this kind of thing is called "nominative use" or "nominative fair use" in the U.S. context. The Python developers are offering a software module so that Python programs, when run on POSIX systems, can make use of capabilities of those systems covered by the POSIX standard. They have named their module
posix so that Python programmers will have a fighting chance of guessing what it does. (The official documentation does say you ought to prefer use of
os instead, but let's ignore that wrinkle.) Likewise, other parts of the standard library contain trademarks of other companies, such as Apple, Microsoft, and Oracle, in relation to Python code which interacts with those companies' products. These are all internal to the Python codebase and documentation, are not distributed separately, and "POSIX" is not part of the name of any product or service offered by the Python Software Foundation. Python is using that word "nominatively", describing some aspect of Python which relates to POSIX but is not POSIX.
The module authors might consider it sensible to use the word "POSIX" in its name and documentation, for the reason that compatibility with POSIX is essential to its functionality. But the rightsholders might also object to its appearance as a bare word (as opposed to
posixinterface or something), because they want to preserve the meaning of "POSIX" as referring to their specific standard, the commercial value of which depends on restricting which operating systems can describe themselves as POSIX-compatible.
In the U.S., circuit courts have taken slightly different directions in trying to carve out whether trademark use like this is OK. In the Second Circuit, there is a recent case about nominative fair use of a certification mark, Int'l Info. Sys. Sec. Certification Consortium v. Sec. Univ., LLC, 823 F.3d 153 (2d Cir. 2016). The plaintiff, (ISC)2, offers the mark "CISSP" for security professionals who have passed certain examinations that they administer. The defendant, SU, offered training classes where the instructor was described as a "Master CISSP", to which the plaintiff objected because consumers could be misled into thinking that (ISC)2 endorsed the classes, and their trademark was being diluted because "Master CISSP" is not a term they use. On appeal, the upper court found that for assessing consumer confusion, courts must consider the eight "Polaroid factors" (named for Polaroid Corp. v. Polarad Electronics Corp., 287 F.2d 492 (2d Cir. 1961) and rephrased in the judgement):
The eight factors are: (1) strength of the trademark; (2) similarity of the marks; (3) proximity of the products and their competitiveness with one another; (4) evidence that the senior user may “bridge the gap” by developing a product for sale in the market of the alleged infringer's product; (5) evidence of actual consumer confusion; (6) evidence that the imitative mark was adopted in bad faith; (7) respective quality of the products; and (8) sophistication of consumers in the relevant market.
(1) whether the use of the plaintiff's mark is necessary to describe both the plaintiff's product or service and the defendant's product or service, that is, whether the product or service is not readily identifiable without use of the mark; (2) whether the defendant uses only so much of the plaintiff's mark as is necessary to identify the product or service; and (3) whether the defendant did anything that would, in conjunction with the mark, suggest sponsorship or endorsement by the plaintiff holder, that is, whether the defendant's conduct or language reflects the true or accurate relationship between plaintiff's and defendant's products or services.
Other circuit courts have adopted subtly different phrasings and this divergence has yet to be resolved by the Supreme Court or by Congress. Whether this standard is met in the example of this question is a matter for argument on the detailed facts.
In the EU, there is an explicit protection for this specific kind of use, by virtue of Article 14 of the latest trademark directive, Directive 2015/2436 of 16 December 2015:
A trade mark shall not entitle the proprietor to prohibit a third party from using, in the course of trade:
(c) the trade mark for the purpose of identifying or referring to goods or services as those of the proprietor of that trade mark, in particular, where the use of the trade mark is necessary to indicate the intended purpose of a product or service, in particular as accessories or spare parts.
Paragraph 1 shall only apply where the use made by the third party is in accordance with honest practices in industrial or commercial matters.
posix library could be regarded as an "accessory" to a POSIX-compatible operating system, in this sense, but is nonetheless within scope if the word "POSIX" is essential to identify what the module does. A key case in the CJEU, concerning a previous version of the Directive but with the same provision, was BMW Nederland BV v Deenik  C-63/97, where a garage owner advertised himself as able to repair BMW cars, with "BMW" being a trademark of the complainants since 1930. The court held that so long as Deenik didn't imply that he had any commercial relationship or endorsement by BMW, he could reasonably use the term "BMW" as part of describing his services.
As with the U.S. system, whether there is actual infringement would depend on the precise situation, and the relevant factors end up being pretty similar. That is partly because of conscious international efforts to harmonize trademark law.