In your first example, where some case affecting the Supreme Court itself came before the Supreme Court then Supreme Court would likely either not hear the case, as most of the grounds you mentioned are invalid and the case would dealt with by lower courts without the need for the Court to get involved, or in the case of a real controversy they would hear the case citing the rule of necessity.
In your second example, where some case naming all Supreme Court justices as parties came before the Court, I'm not entirely sure what would happen. In cases where four or more justices haven been named, but not all nine, the court has affirmed the appeals court decision for lack quorum. If a case naming all the justices (or even just four or more) involved a real issue of law that needed to be decided, it's likely the rule of necessity would also apply here, but I don't think anything like has ever happened. Otherwise my guess is that the justices just let the case sit in judicial limbo, seeing no need to make a decision regarding it.
All federal judges are required disqualify (recuse) themselves whenever their "impartiality might be reasonably questioned." (28 USC 455) That not only includes cases that the judge is a party to, but any case where the ruling might be benefit or be disadvantage the judge, as well other circumstances like where the judge as personal bias against one of the parties. As such, there's a long history of such cases where the judge or judges are required by law to disqualify themselves, including cases before the Supreme Court.
However the common law rule of necessity applies when all judges capable of hearing a case would be disqualified. This rule prevents the judges from being disqualified, and allows the case to go forward, when disqualification would prevent any court from hearing the case. This rule was asserted by the Supreme Court in United States v. Will (449 US 200), a case involving the compensation of all federal judges including the justices themselves. The Court determined that not only was the district judge right not to disqualify himself, the Supreme Court justices couldn't do so either:
Far from promoting 455's purpose of reaching disqualification of an individual judge when there is another to whom the case may be assigned, failure to apply the Rule of Necessity in these cases would have a contrary effect by denying some litigants their right to a forum. And the public might be denied resolution of the crucial matter involved if first the District Judge and now all the Justices of this Court were to ignore the mandate of the Rule of Necessity and decline to answer the questions presented.
The rule of necessity would not only apply when a case affects all federal judges but also more broadly, when it affects all US citizens or residents. A hypothetical case on income tax or jury duty would also affect all judges, so the Supreme Court could still hear the case despite there being good reason question their impartiality.
However, in a case where only the impartiality of the Supreme Court justices and not judges generally is being questioned, and where the case being heard is a direct appeal from a district court, then US law (28 USC 2109) allows the Chief Justice to remit the cast to a Court of Appeals for a final decision. However direct appeals to the Supreme Court are only allowed in limited circumstances, like when a federal law is deemed unconstitutional.
The same US law also requires that if a case not on direct appeal can't be heard by the Supreme Court because of disqualification reduces the number of qualified justices to below the quorum threshold of six, and a majority of the remaining qualified justices determine that quorum can't be achieved during the next term then the appeals court decision is affirmed. Note however this requires that at least one justice not be disqualified.
So if a district judge determined that some law affecting the Supreme Court was constitutionally invalid, and was appealed directly to the Supreme Court, then I would expect the Supreme Court justices to disqualify themselves and refer the case to the appropriate Court of Appeals. If the case came through the appeals court(s) then rule of necessity applies one way or another, as the court can't even deny certiorari without a quorum of qualified justices. That would be the most likely outcome if the appeals court decision was one the Supreme Court agreed with or didn't find controversial enough to deal with. On the other hand, if different appeals courts came to different conclusions about the law then they'd be forced to hear the case by the rule of necessity.
In the other example you gave, where the Supreme Court justices are named as parties in a case before them does actually happen to time to time. I'm not sure what happens when all justices are named, but there's a number of examples of cases where enough justices are named to reduce the number of qualified justices to below six. In that case the practice of the court seems to be to affirm the appeals court decision for lack quorum as required by 28 USC 2109. In cases like these it's very unlikely that appeals court has come to a controversial decision anyways, almost certainly upholding a district court's decision to dismiss some groundless lawsuit against the justices.
There's an interesting recent case, Deutsche Bank Trust Company Americas v. Robert R. McCormick Foundation, where Supreme Court apparently had to walk a fine line between avoiding the appearance of a conflict interest while not affirming an appeals court decision that they had essentially overruled in another Supreme Court case. In the Deutsche Bank case, all but two Supreme Court justices apparently had a conflict of interest, likely a financial one given that a large number of big retirement funds were involved. The Court neither affirmed the appeals court decision for lack of quorum, denied certiorari, nor heard the case. Instead the two apparently unconflicted justices decided to defer the case to "allow the Court of Appeals or the District Court to consider whether to recall the mandate, entertain a Federal Rule of Civil Procedure 60(b) motion to vacate the earlier judgment, or provide any other available relief in light of this Court’s decision in Merit Management Group."
The problem the Supreme Court faced was that in the Merit Management Group decision the Court invalidated the basis the appeals court had used in deciding the Deutsche Bank case. Normally in such circumstances the Supreme Court would grant certiorari and then immediately vacate the judgement and send it back for reconsideration by the appeals court. Affirming the appeal court decision for lack of quorum would effectively contradict their recent Merit decision. Invoking the rule of necessity would be awkward at best in a situation where there were other judges are able to decide the issue, but there was no formal way for the Court to remit the case to them. So they kicked the can down the street, asking the appeals court to take the problem off their hands. Ultimately that's what happened, and the Supreme Court case was dismissed without the Court having to make a ruling whether to even hear the case.