I just spent a little over two weeks in Spain and Portugal. Of that time, the most over-rated and, to me, biggest waste of time, was the Pena Palace. I wouldn't go back nor would I recommend it to anyone as a "primary" place to visit while in Lisbon. I did really enjoy the Moorish Castle, but the Pena Palace was just a big stand-in-line and shuffle through rooms time waste, so your plans to not go inside are a good idea.
To your question, we bought tickets to the Moorish Castle on the day of at the TI in the train station and I bought our Pena Palace tickets online as we were walking up from the train station to the palace. Buying day off for the Pena Palace was a little risky as they did have a limit, but that limit was exceptionally high (hence the crowds and lines).
We did the walk up from the train station and the walk down back to the station, and it was steep and slow going during periods of light rain, but I think the walk itself and the views from the Moorish castle ruins were by far my favorite part of that day trip. Even so, I sort of wish we had devoted that day more to Lisbon and not made the easy train trip out and back to Sintra.