That is a syntax error as according to the Syntax Diagram for SQLite Triggers we can't have any IF or CASE clause between BEGIN and END.
So you should create two triggers for different operations like this:
1) For Delete Case
CREATE TRIGGER trig1
AFTER
UPDATE OF flag
ON table1
FOR EACH ROW
WHEN NEW.flag=0
BEGIN
DELETE FROM stats WHERE app_id=NEW.id AND ondate=CURRENT_DATE and runtime=0;
END;
2) For Insert Case
CREATE TRIGGER trig2
AFTER
UPDATE OF flag
ON table1
FOR EACH ROW
WHEN NEW.flag=1
BEGIN
INSERT OR IGNORE INTO stats VALUES(NEW.id,CURRENT_DATE,0);
END;