The other answers cover the basic requirements, so I'll get to a requirement not mentioned. To comply with the National Electrical Code (NEC), replacing a receptacle requires Arc-Fault Circuit-Interrupter (AFCI) protection. This has been a requirement since 2014. There are variations of adoption by state and local ordinance, but the NEC requires AFCI protection in most locations in a house, except bathrooms. An example of a state difference is Idaho, where AFCI protections is only required in bedrooms. California adopted all NEC requirements. Also, tamper-resistant outlets are a requirement in changing receptacles.
To recap requirements:
Non-grounding: You are allowed to replace a non-grounding (2-prong) receptacle with another non-grounding receptacle, but I've found none available for sale. So this option is likely only available if you have extras on hand, or get them another way, perhaps replacing a broken receptacle with one salvaged when you upgrade another branch to grounding receptacles. Tamper-resistance is not required for non-grounding receptacles. However, the NEC does not exclude the AFCI requirement if the replacement is in an area that requires AFCI protection, which complicates the simple replacement of a damaged 2-prong receptacle with the same.
GFCI: But in most cases, people want to install a 3-prong grounding receptacle. Without upgrading the wiring (running hot neutral ground), GFCI protection is required. That means, for a given branch circuit, either a GFCI breaker at the panel, a GFCI receptacle that can feed regular 3-prong receptacles as loads downstream on the branch, or more GFCI receptacles to attain complete coverage—at the extreme that means a GFCI receptacle at each outlet.
Tamper-resistance: All receptacles need to be tamper-resistant, whether plain or GFCI.
AFCI: In addition, the NEC requires AFCI protection as prescribed. Because of code difference, you should find the requirements for your location (state, and possibly county, city). Per the NEC, bathrooms are excluded, and some large appliances. Basically, the protection is most important where people might plug in many items (bedrooms, living rooms, kitchens, garages), and a spark could cause a fire. Large appliances with motors can trip AFCI protection unnecessarily, hence the exclusions. Bathrooms are primarily a water hazard, and are excluded.
For a branch that requires AFCI protection, the options are similar to GFCI. You can get an AFCI breaker—including a combination AFCI/GFCI breaker. You can use AFCI outlets—including combination AFCI/GFCI breakers.
You're required to tag ungrounded outlets properly—"No Equipment Ground" for GFCI ungrounded outlets, and both "GFCI Protected" and "No Equipment Ground" on protected standard outlets (stickers come with GFCI receptacles).
Note: These requirements greatly complicate updating old outlets. I'm giving an overview of the important details—check code or hire an electrician as needed. I'm not saying the police will be knocking at your door to check your outlets. But if you do a lot of work and your place burns down, or someone gets injured, maybe your insurance provider or other party may consider negligence, and that may even happen after you've sold your house to someone else. Either way, it's good to know what requirements are before taking on such an upgrade task. Maybe you intend to be 100% compliant with code, do all the work, then find out a few months later no one mentioned AFCI, etc., and you could have taken care of it the first time.
Code access:
You can get free access to the NEC—here's the 2023 code: National Electrical Code 2023
You can find state and major local codes here, choose your state and click Electrical Code: Building Codes