Can we perform sajadatus sahv when we are walking or riding? If not, how should we perform it if during nafilah namaz we commit an act that necessitates sajatus sahv?

Sajdatul sahv is not wajib in nafilah zamaz at all. it's is only in wajib Namaz.