How can I stop my servo looping when my sensor doesn't detect movement?
Don't set the pos to 180 in the (digitalRead(pir) == LOW) branch if you do not want it to repeatedly jump up to 180 for as long as the condition is true.
void loop() {
  if (digitalRead(pir) == HIGH)
     pos = 180;
  myservo.write(pos);              // tell servo to go to position in variable 'pos'
    
  Serial.print(&quot;Motion detected!&quot;);

  if (digitalRead(pir) == LOW)
    for (; pos &gt; 0; pos -= 1) { // decay to 0 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    
  Serial.print(&quot;Motion ended!&quot;);
}

Alternately, you could use pos as a state variable and simplify things:
void loop() {
  if (digitalRead(pir) == HIGH)
     pos = 180;
  elif (pos &gt; 0 ){
     pos--;
     delay(15);
  }
  myservo.write(pos);
}