SD card initialization fails randomly
I have seen SD cards that do not like this section of code:

  // command to go idle in SPI mode
  while (cardCommand(CMD0, 0) != R1_IDLE_STATE) {
    if (((uint16_t)millis() - t0) &gt; SD_INIT_TIMEOUT) {
      error(SD_CARD_ERROR_CMD0);
      goto fail;
    }
  }


Some SD cards (mine, of course) seem to need a little quiet time to finish their INIT process.  Adding a delay of &lt;something&gt; made the INIT process complete successfully, first time through the loop.

I'm guessing that the SD card spends so much time handling the repeated CMD0 commands (continuously sent by above loop) that they don't get to spend time on the INIT process.  IIRC, the standard says the card is allowed to take up to 2 seconds to INIT (!).  I can't recall, but I think I tried 150ms or so:

  // command to go idle in SPI mode
  while (cardCommand(CMD0, 0) != R1_IDLE_STATE) {
    delay( 150 ); // let SD get some time to work
    if (((uint16_t)millis() - t0) &gt; SD_INIT_TIMEOUT) {
      error(SD_CARD_ERROR_CMD0);
      goto fail;
    }
  }


I do recall that reinserting the card would sometimes make it work.  I have suggested this to at least one SD card library maintainer, but I think we're all reluctant to impose a delay on all cards.  OTOH, it is just during ::begin.

It might work for you, though.  The above snippet is from SdSpiCard.cpp, but you may have to go looking for it in other places, depending on which library and version you're using.