Take off the next piece of pipe, remove old capture nut, add new one, reassemble
The next piece seems to screw onto the stub with a compression nut. Loosen it slightly and it should pop out. Fully agree that the pieces should be cleaned out before reassembling. I see plumbers tape or pipe dope, that shouldnt be there