I have the following pipe coming out of the wall. It seems to me that I would need a p trap that screws onto the existing thread but all drain plumbing I have seen so far (e.g., https://www.lowes.com/pd/Keeney-1-1-2-in-Plastic-P-Trap/1076241) appears to have the plastic connecting downward (it has its own thread and you use the top part to secure it to the drain). Am I missing something?
You need to find the rest of that trap or purchase a new one. If you can not find a trap that matches yours you will need to cut the old stuff off and start with a new trap kit. I have found even 30+ year old plumbing matches up to brand new pieces. Take this photo to a plumbing store or big box and they can set you up for 3-15$. The house ghee price if you have to cut and replace the lower for the bend with a nut.