If you are taking an Uber/bolt from Lisbon, do not stop in the town. Keep going.
The Uber/bolt will drop you off up in the mountain at the entrance to the Pena Park (ticket office if you have not already purchased ticket). From the park entrance, there is still a 10 to 15 minute walk to the Palace itself. Or, you can pay for the shuttle bus from there.
To get to the Moorish Castle, you walk back down to the park entrance and then you walk about 5 minutes on the roadway in opposite direction of the one-way driving direction. Once you get to the ticket office for the Moorish castle, you still have to walk on a trail for about 10-15 minutes to get to the castle itself. I suggest that you do the Pena Palace before you do the Moorish Castle. The crowds at the Pena Palace really build up as the day wears on. You can get into the Moorish Castle at any time. Good luck.