If I understand what you're trying to do, you don't necessarily want stop stamina drain when you're colliding with a wall, but when you're not moving (that is, when you're running in place because a wall is in the way).
So, it should be best to check for movement rather than collision. Specifically, you can check your motion var's X axis for absolute values above delta (bumping into a wall will still produce a tiny amount of movement, so we want a threshold).
(also, you probably want to pair this with whatever you're using for floor detection if applicable. Moving left/right through the air probably shouldn't drain stamina either!)
var max_stamina = 200
var stamina = 200 setget _set_stamina
var stamina_burn_rate = 15 #burn 15/sec when running
var stamina_recovery_rate = 5 #recover 5/sec
func _set_stamina(value):
stamina = clamp(value,0,max_stamina) #keep from under/overflowing
func _fixed_process(delta):
var motion = (motion vector got from input and stuff)
motion = move(motion) # any 'leftover' motion will be returned
var Mx = abs(motion.x)
var new_stamina = stamina
if Mx > delta:
new_stamina = stamina - (stamina_burn_rate*delta)
elif Mx == 0:
new_stamina = stamina + (stamina_recovery_rate*delta)
if new_stamina != stamina:
set('stamina', new_stamina)