For reference, this is from the NEC 2020 Article 406 Receptacles (etc) on replacement of non-grounding receptacles.
406.4 (D) Replacements. Replacement of receptacles shall comply with 406.4(D)(1) through (D)(7), as applicable. Arc-fault circuit-interrupter type and ground-fault circuit-interrupter type
receptacles shall be installed in a readily accessible location.
(1) Grounding-Type Receptacles. Where a grounding means exists in the receptacle enclosure or an equipment grounding conductor is
installed in accordance with 250.130(C), grounding-type receptacles
shall be used and shall be connected to the equipment grounding
conductor in accordance with 406.4(C) or 250.130(C).
A(2) Non-Grounding-type Receptacles. Where attachment to an equipment grounding conductor does not exist in the receptacle
enclosure, the installation shall comply with 406.4(D) (2) (a), (D)
(2) (b), or (D) (2) (c).
(a) A non-grounding-type receptacle(s) shall be permitted to be replaced with another non-grounding-type receptacle(s).
(b) A non-grounding-type receptacle (s) shall be permit¬ ted to be replaced with aground-fault circuit interrupter-type of receptacle
(s).
These receptacles or their cover plates shall be marked “No Equipment Ground.” An equipment grounding conductor shall not be
connected from the ground-fault circuit-interrupter-type receptacle to
any outlet supplied from the ground-fault circuit-interrupter
receptacle,
(c) A non-grounding-type receptacle (s) shall be permitted to be replaced with a grounding-type receptacle (s) where supplied
through a ground-fault circuit interrupter. Where grounding-type
receptacles are supplied through the ground-fault circuit interrupter,
grounding-type receptacles or their cover plates shall be marked “GFCI
Protected” and “No Equipment Ground,” visible after installation. An
equipment grounding conductor shall not be connected between the
grounding type receptacles.
If you have an ungrounded system, and would like to replace the old 2 prong receptacles with grounded receptacles (3-prong) then there are code accepted methods to do so.
Please refer to NEC Article 406.4 for these methods.