The theory on the federal level is "this judge was appointed by president X-1, so they aren't influenced by president X". So for better or worse (depending on which president that filled the vacancy), they may go against what is popular in administration X. The federal supreme court tries to be shielded away from the immediate politics of worrying about re-election and stuff.
On the state level, well... as usual it's a free for all. Just to list the "hot" states of subject:
- Texas: the people vote for them, 6 year term. no different from voting for a senator/representative. - Florida: More complex, but in short: the governor chooses from a list of candidates handed to them, and the chosen judge serves one term (4 years) before the people decide to keep them or not.
So the people on the state level here have some sway. But then again, the people here are... well, Texas/Florida people.