Absolutely, it isn't illegal.
There is a time to express your preference for one party or candidate. That is the general election. If you switch to vote for a primary candidate in order to prevent a more viable candidate from winning the nomination, it seems to me your using two opportunities to attempt to get your favored candidate elected. The point of an election is to vote for the candidate you favor, not to vote to prevent other people from selecting the candidate they favor.
I assume you mean Pennsylvania for the Republicans? I disagree with anyone voting for someone for the purpose of mucking up the other party's primary, or in the hopes that the other party will get stuck with the least viable candidate. However, I have less qualms about someone who knows they will vote Republican in the general election voting for what they perceive to be the best candidate of the other party. Ideally, I think one should only vote for a candidate if they believe they could vote for them in the general election. So to recap, I disagree with position 1, am abivalent to position 2, and wholly endorse position 3.